Skip to content

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

@bk-mja

Description

@bk-mja

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?

someDate.toString()

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

😯 Current Behavior

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

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/[email protected]

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions