Skip to content

Interval hasSame minus(1) #1710

@sam-s4s

Description

@sam-s4s

Interval.hasSame does a minus(1) on the end date in the calculation, which breaks all comparisons when the end date time has "00:00:00.000" for the time component (for example). It will also break some non-0 time component comparisons, especially when miliseconds are 0).

As per...
https://github.com/moment/luxon/blob/master/src/interval.js#L268
The code is...

return this.isValid ? this.isEmpty() || this.e.minus(1).hasSame(this.s, unit) : false;

A previous issue resolves one bug in hasSame, and @icambron says "That subtraction is meant to make the interval half-open"...
#709

However I am not sure what "half-open" means, or why you would want that behaviour... It literally means that if you pass in a 0 time component, you will always get incorrect results back.

Maybe I'm missing something - is there ever a case where you would want to minus(1) from the end date time?

I have not been able to think of any scenario where you would want to do minus(1), and thus am proposing to remove that piece of code.

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