luxon
luxon copied to clipboard
Interval inconsistent in returning values
Describe the bug Interval returns different values
To Reproduce
const interval = Interval.fromDateTimes(DateTime.local().minus({ days: 60 }), DateTime.local()) .splitBy({ days: 1 }); console.log(interval.length);
Actual vs Expected behavior Actual: 60 or 61 Expected: 61
- OS:Linux
- Luxon version: 1.26.0
Just depends on whether the two local()
calls resolved in the same millisecond or not. If you assign that to a local var and use it both places, does it still happen?
I cannot reproduce this issue if only one call to local
is used.
If two calls are used, the case of 61 intervals does happen occasionally, in that case the last interval contains only one millisecond. This proves the comment above - two calls to local
are not guaranteed to produce the same timestamp, no matter how quickly you call them.