#1808·luxon

Interval#isEmpty() throws TypeError on an Invalid interval instead of returning false (unlike its siblings)

Author: manqingzhouCreated Sep 21, 2026Updated Sep 21, 2026

Describe the bug

Interval#isEmpty() reads this.s.valueOf() directly with no isValid guard — unlike its siblings isAfter, isBefore, contains, and engulfs, which all start with if (!this.isValid) return false;. On an Invalid Interval (e.g. produced by an end-before-start range, or Interval.invalid(...)), this.s is undefined, so isEmpty() throws TypeError: Cannot read properties of undefined (reading 'valueOf') instead of returning a boolean — breaking the "Invalid objects don't throw" contract the rest of the Interval API follows.

To Reproduce

javascript
import { Interval } from 'luxon';

const iv = Interval.fromISO('2024-06-01T12:00Z/2024-06-01T06:00Z'); // end < start -> Invalid
console.log(iv.isValid); // false
iv.isEmpty(); // throws TypeError: Cannot read properties of undefined (reading 'valueOf')

Interval.invalid('whatever').isEmpty(); // throws the same way

Verified against the actual 3.7.2 source; both calls throw as described.

Actual vs Expected behavior

Actual: isEmpty() throws an uncaught TypeError on any Invalid interval. Expected: like its siblings, it should return false for an Invalid interval instead of throwing.

Desktop (please complete the following information):

  • Luxon version: 3.7.2 (current latest; verified against source at GitHub tag 3.7.2)
  • Node: v24.16.0

Additional context

Suggested fix — a one-line guard matching the pattern already used four times elsewhere in src/interval.js:

javascript
isEmpty() {
  if (!this.isValid) return false;
  return this.s.valueOf() === this.e.valueOf();
}

Might be worth a quick audit of the other Interval/DateTime/Duration instance methods for the same unguarded-this.s/this.e pattern, and/or a small generated test that calls every public method on Interval.invalid("test") and asserts none of them throw.