adobe / adobe/react-spectrum

CalendarDate.toString() can return non ISO 8601 formatted strings

Open
#9,255 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
15.9k
Forks
1.6k
Avg merge
3d 9m
Merged PRs (30d)
59

Description

### Provide a general summary of the issue here

When adding a non integer number of days to a CalendarDate, the output of `toString()` is no ISO 8601 string anymore, but something like `'2025-11-2.0000002'`.

### 🤔 Expected Behavior?

```typescript
someDate.toString()
```
always converts the date to an ISO 8601 formatted string (as per docs).
For example `'2025-10-28'` .

### 😯 Current Behavior

```typescript
someDate.toString()
```
can return strings like `'2025-10-28.0000002'`, which is not conforming to ISO 8601 .

### 💁 Possible Solution

One possible solution would be to round to the nearest full day when calculating the output string.

Another way to solve this issue is not allowing non decimal values for `year`, `month`, and `day` in the first place by either throwing an error when given a non integer input, or rounding to the nearest number. However, im not sure what implication this would have. Throwing an error would certainly be a breaking change.
As the CalendarDate object is supposed to represent date without any time components, I think not allowing decimal numbers by rounding them could be a reasonable solution here.

### 🔦 Context

I've ran into this issue in our production app, as i was feeding some drag and drop offset into the add function that had a rounding error. You could argue that it is the users responsibility to sanitize the input here, however i feel like this is never the intended behavior, so a fix on the library level feels appropriate.
In my example I used the output of `toString()` to submit the resulting value to my backend which couldn't parse it back to a date.

### 🖥️ Steps to Reproduce

```typescript
const dateA = new CalendarDate(2025, 10, 28);
const dateB = dateA.add({days: 0.0000002});
dateB.toString() // '2025-10-28.0000002'
```

CodeSandBox: https://codesandbox.io/p/devbox/angry-framework-8k5klq

### Version

@internationalized/date@3.9.0

### What browsers are you seeing the problem on?

Microsoft Edge

### If other, please specify.

_No response_

### What operating system are you using?

MacOS

### 🧢 Your Company/Team

_No response_

### 🕷 Tracking Issue

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.