angular/components · error · Error

Invalid minutes "${minutes}". Minutes value must be between

Error message

Invalid minutes "${minutes}". Minutes value must be between 0 and 59.

What it means

setTime validates minutes to the 0-59 range in dev mode; out-of-range minutes would silently roll into hours (60 minutes -> +1 hour) via Date overflow. The adapter throws instead to keep the resulting Date faithful to the requested components.

Source

Thrown at src/material/core/datetime/native-date-adapter.ts:251

    return obj instanceof Date;
  }

  isValid(date: Date) {
    return !isNaN(date.getTime());
  }

  invalid(): Date {
    return new Date(NaN);
  }

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

      if (!inRange(minutes, 0, 59)) {
        throw Error(`Invalid minutes "${minutes}". Minutes value must be between 0 and 59.`);
      }

      if (!inRange(seconds, 0, 59)) {
        throw Error(`Invalid seconds "${seconds}". Seconds value must be between 0 and 59.`);
      }
    }

    const clone = this.clone(target);
    clone.setHours(hours, minutes, seconds, 0);
    return clone;
  }

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

  override getMinutes(date: Date): number {
    return date.getMinutes();

View on GitHub (pinned to 0411926e7d)

Solutions

  1. Clamp/validate minutes to 0-59 before calling setTime.
  2. Split excess into hours: setTime(target, h + Math.floor(min/60), min % 60, s).
  3. Use adapter.addCalendarMinutes for duration math instead of raw component setting.

Example fix

// before
adapter.setTime(target, 9, 75, 0);
// after
adapter.addCalendarMinutes(adapter.setTime(target, 9, 0, 0), 75);
Defensive patterns

Strategy: validation

Validate before calling

if (!Number.isInteger(minutes) || minutes < 0 || minutes > 59) {
  throw new RangeError(`minutes must be 0-59, got ${minutes}`);
}
adapter.setTime(target, hours, minutes, seconds);

Type guard

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

Try / catch

try {
  adapter.setTime(target, h, minutes, s);
} catch (e) {
  if (e instanceof Error && e.message.includes('Invalid minutes')) {
    const carry = Math.floor(minutes / 60);
    adapter.setTime(target, h + carry, minutes % 60, s);
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling adapter.setTime(target, h, minutes, s) with minutes < 0 or > 59, typically from unvalidated parsed time strings (_parseTimeString) or duration addition like minutes = 75.

Common situations: Free-text time inputs ('9:75'), summing durations into a minutes field, off-by-one when converting seconds to minutes and seconds.

Related errors


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