luxon icon indicating copy to clipboard operation
luxon copied to clipboard

Interval inconsistent in returning values

Open webspin opened this issue 3 years ago • 1 comments

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

webspin avatar Feb 15 '21 16:02 webspin

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?

icambron avatar Feb 15 '21 21:02 icambron

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.

diesieben07 avatar Feb 28 '23 22:02 diesieben07