angular/components · error · Error

Invalid seconds "${seconds}". Seconds value must be between

Error message

Invalid seconds "${seconds}". Seconds value must be between 0 and 59.

What it means

The Material Luxon date adapter's setTime validates the seconds argument before applying it to the target DateTime. Seconds must be a whole number between 0 and 59; anything outside that range would produce an invalid Luxon DateTime, so the adapter throws a descriptive error in ngDevMode instead. This mirrors the same guards applied to hours and minutes.

Source

Thrown at src/material-luxon-adapter/adapter/luxon-date-adapter.ts:286

  }

  override setTime(
    target: LuxonDateTime,
    hours: number,
    minutes: number,
    seconds: number,
  ): LuxonDateTime {
    if (typeof ngDevMode === 'undefined' || ngDevMode) {
      if (hours < 0 || hours > 23) {
        throw Error(`Invalid hours "${hours}". Hours value must be between 0 and 23.`);
      }

      if (minutes < 0 || minutes > 59) {
        throw Error(`Invalid minutes "${minutes}". Minutes value must be between 0 and 59.`);
      }

      if (seconds < 0 || seconds > 59) {
        throw Error(`Invalid seconds "${seconds}". Seconds value must be between 0 and 59.`);
      }
    }

    return this.clone(target).set({
      hour: hours,
      minute: minutes,
      second: seconds,
      millisecond: 0,
    });
  }

  override getHours(date: LuxonDateTime): number {
    return date.hour;
  }

  override getMinutes(date: LuxonDateTime): number {
    return date.minute;
  }

View on GitHub (pinned to 0411926e7d)

Solutions

  1. Clamp or validate seconds to 0-59 before calling setTime (e.g. Math.min(59, Math.max(0, seconds))).
  2. If you have milliseconds, convert first: Math.floor(ms / 1000) % 60.
  3. Verify argument order — seconds is the fourth parameter of setTime; a transposed argument list is common.
  4. Fix the upstream calculation producing the out-of-range value (unit test the arithmetic).

Example fix

// before
adapter.setTime(date, 10, 30, inputSeconds); // inputSeconds could be 75
// after
const safeSeconds = Math.min(59, Math.max(0, Math.floor(inputSeconds)));
adapter.setTime(date, 10, 30, safeSeconds);
Defensive patterns

Strategy: validation

Validate before calling

function canSetTime(seconds: number): boolean {
  return Number.isInteger(seconds) && seconds >= 0 && seconds <= 59;
}
if (!canSetTime(seconds)) seconds = Math.min(59, Math.max(0, Math.floor(seconds)));

Type guard

function isValidSeconds(s: unknown): s is number {
  return typeof s === 'number' && Number.isInteger(s) && s >= 0 && s <= 59;
}

Try / catch

try {
  adapter.setTime(date, h, m, s);
} catch (e) {
  if (e instanceof Error && e.message.includes('Invalid seconds')) {
    adapter.setTime(date, h, m, Math.min(59, Math.max(0, Math.floor(s))));
  } else throw e;
}

Prevention

When it happens

Trigger: Calling setTime(target, hours, minutes, seconds) on a LuxonDateAdapter with seconds < 0 or seconds > 59, e.g. computing seconds from a buggy formula, parsing user input without clamping, or accidentally passing milliseconds (e.g. 250) as seconds.

Common situations: Passing a Date.getSeconds()-style value that is actually milliseconds, off-by-one or arithmetic mistakes when deriving seconds from a timestamp, unvalidated form fields, or locale/timezone code that subtracts time offsets producing negative values.

Related errors


AI-assisted analysis of angular/components@0411926e7d (2026-08-31). Data as JSON: /api/errors/7d7b85f271e3f31e. Report an issue: GitHub.