react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

fromAbsolute in @internalization/date parses dates BC incorrectly

Open KimPeeters opened this issue 8 months ago โ€ข 0 comments

Provide a general summary of the issue here

When using fromAbsolute on a number less then -62135596800000 (0001-01-01T00:00:00Z) results in the correct date and time except the year is always 0001 AD.

๐Ÿค” Expected Behavior?

When using the absolute value -62135596800001 i would expect the date to be 0000-12-31T23:59:59.999Z.

๐Ÿ˜ฏ Current Behavior

Currently -62135596800001 results in 0001-12-31T23:59:59.999Z

๐Ÿ’ Possible Solution

Replacing the return value in the fromAbsolute function with:

return new ZonedDateTime(year < 1 ? "BC" : "AD", year < 0 ? Math.abs(year) + 1 : year, month, day, timeZone, offset, hour, minute, second, millisecond);

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

import { fromAbsolute } from "@internationalized/date";

console.log(fromAbsolute(-62135596800000, "UTC").toAbsoluteString()); console.log(fromAbsolute(-62135596800001, "UTC").toAbsoluteString());

Version

3.5.4 (@internationalized/date)

What browsers are you seeing the problem on?

Chrome, Microsoft Edge

If other, please specify.

No response

What operating system are you using?

Windows

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

KimPeeters avatar Jun 13 '24 10:06 KimPeeters