luxon
luxon copied to clipboard
fromJSDate produce invalide
Description fromJSDate with the max valid JS Date produce invalid luxon DateTime.
To Reproduce
const jsdate = new Date(8640000000000000); const dt = DateTime.fromJSDate(jsdate); console.log( dt.invalidReason );
Actual vs Expected behavior fromJSDate with a valid JSDate should be a valid luxon DateTime
Desktop:
- Browser [Chrome 88, Firefox 85]
- NodeJs 14
- Luxon version 1.26.0
Additional context new Date(8639999992800000) is the max possible value. new Date(8639999992800001) is invalid. new Date(-8640000000000000) works also.
This looks to be because when luxon constructs a DateTime, it does so using the default zone.
As part of this process it constructs a new Date object, which is the passed date plus the relevant offset for the default zone. This new Date is then used to create the return values for the year/month/day etc methods.
As the passed date is already at the limit for Dates, adding anything to it produces an invalid Date and an invalid DateTime.
Constructing a date with no offset, e.g. DateTime.fromJSDate(new Date(8640000000000000), {zone: 'UTC'})
, creates a valid DateTime.
I'm not sure this is a bug - effectively you're asking luxon to create a Date larger than JavaScript can represent - but it might be worth documenting.