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

MomentDateAdapter.setTime validates the minutes argument (0-59) before applying it. Minutes outside that range would roll over into hours or create an invalid value, so the adapter throws this explicit ngDevMode error, alongside its sibling checks for hours and seconds.

Source

Thrown at src/material-moment-adapter/adapter/moment-date-adapter.ts:252

    return moment.isMoment(obj);
  }

  isValid(date: Moment): boolean {
    return this.clone(date).isValid();
  }

  invalid(): Moment {
    return moment.invalid();
  }

  override setTime(target: Moment, hours: number, minutes: number, seconds: number): Moment {
    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({hours, minutes, seconds, milliseconds: 0});
  }

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

  override getMinutes(date: Moment): number {
    return date.minutes();
  }

View on GitHub (pinned to 0411926e7d)

Solutions

  1. Convert first: if you have minutes-of-day, compute hour = Math.floor(m/60), minute = m % 60 and pass both correctly.
  2. Clamp minutes to 0-59 after validating upstream data.
  3. Check arithmetic producing minutes for unit issues (seconds vs minutes vs ms).
  4. Verify setTime argument order: (target, hours, minutes, seconds).

Example fix

// before
adapter.setTime(date, 0, minutesOfDay, 0); // minutesOfDay can be 725
// after
adapter.setTime(date, Math.floor(minutesOfDay / 60), minutesOfDay % 60, 0);
Defensive patterns

Strategy: validation

Validate before calling

function canSetTime(h: number, m: number, s: number): boolean {
  return [h, m, s].every(Number.isInteger) && h >= 0 && h <= 23 && m >= 0 && m <= 59 && s >= 0 && s <= 59;
}

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(date, h, m, s);
} catch (e) {
  if (e instanceof Error && e.message.includes('Invalid minutes')) {
    const total = h * 60 + m;
    adapter.setTime(date, Math.floor(total / 60) % 24, total % 60, s);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling setTime(target, hours, minutes, seconds) with minutes < 0 or > 59, e.g. passing total minutes of the day (0-1440) as the minute field, or negative values from subtracting offsets.

Common situations: Confusing 'minutes of day' with 'minutes of hour', duration math passed directly as the minutes component, timezone-offset subtraction producing negative minutes, transposed argument order.

Related errors


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