Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interval.intersection() on abutting intervals returns a 0-length interval instead of null #927

Closed
0x24a537r9 opened this issue May 1, 2021 · 0 comments

Comments

@0x24a537r9
Copy link
Contributor

0x24a537r9 commented May 1, 2021

Describe the bug
Interval.intersection() on abutting intervals returns a 0-length interval, in spite of https://moment.github.io/luxon/docs/class/src/interval.js~Interval.html#static-method-fromDateTimes saying that Interval is "Inclusive of the start but not the end". The docstring for intersection also says explicitly "Returns null if the intersection is empty, meaning, the intervals don't intersect."

To Reproduce

test('intersection of abutting intervals is null', () => {
  expect(
    Interval.fromISO('2021-01-01T09:00:00Z/2021-01-01T10:00:00Z').intersection(
      Interval.fromISO('2021-01-01T10:00:00Z/2021-01-01T11:00:00Z'),
    ),
  ).toBeNull();
});

Actual vs Expected behavior
If Interval is indeed meant to be inclusive of the start but not the end, then the overlap should be null. Instead I get for the test above:

    expect(received).toBeNull()

    Received: {"e": "2021-01-01T02:00:00.000-08:00", "invalid": null, "isLuxonInterval": true, "s": "2021-01-01T02:00:00.000-08:00"}

      1110 |         Interval.fromISO('2021-01-01T10:00:00Z/2021-01-01T11:00:00Z'),
      1111 |       ),
    > 1112 |     ).toBeNull();
           |       ^
      1113 |   });
      1114 |
      1115 |   // tech with null rules

It's worth noting that Interval.overlaps() works as expected, with the following test passing:

test('overlaps of abutting intervals is false', () => {
  expect(
    Interval.fromISO('2021-01-01T09:00:00Z/2021-01-01T10:00:00Z').overlaps(
      Interval.fromISO('2021-01-01T10:00:00Z/2021-01-01T11:00:00Z'),
    ),
  ).toBe(false);
});

Conceptually, I think that Interval.overlaps() should be perform identically to Interval.intersection() != null.

Desktop (please complete the following information):

  • OS: Mac
  • Browser: Node
  • Luxon version: ^1.26.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant