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
MomentDateAdapter.setTime validates the seconds argument (0-59) before calling Moment's set(). Out-of-range seconds would roll into minutes or produce garbage, so the adapter throws this explicit ngDevMode error, matching the hours and minutes guards in the same method.
Source
Thrown at src/material-moment-adapter/adapter/moment-date-adapter.ts:256
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();
}
override getSeconds(date: Moment): number {
return date.seconds();
}
View on GitHub (pinned to 0411926e7d)
Solutions
- Clamp seconds to 0-59 before the call.
- Convert milliseconds: Math.floor(ms / 1000) % 60, or pass ms via a separate set() call.
- Check the upstream computation for unit confusion.
- Confirm argument order (target, hours, minutes, seconds).
Example fix
// before adapter.setTime(date, h, m, msSinceMinute); // ms, not seconds // after adapter.setTime(date, h, m, Math.floor(msSinceMinute / 1000));
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 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
- Convert ms to seconds explicitly (floor(ms/1000) % 60) before setTime
- Clamp seconds at input boundaries
- Avoid passing raw timestamp remainders as components
- Assert component ranges in tests around time math
When it happens
Trigger: Calling setTime(target, hours, minutes, seconds) with seconds < 0 or > 59 — e.g. passing milliseconds as seconds, epoch-derived values not taken mod 60, or negative results from offset math.
Common situations: Timestamp math leaks (timestamp % 1000 passed as seconds), leap-second or offset-subtraction producing -1, unvalidated network data, argument transposition.
Related errors
- Invalid hours "${hours}". Hours value must be between 0 and
- Invalid minutes "${minutes}". Minutes value must be between
- Invalid month index "${month}". Month index has to be betwee
- Invalid date "${date}". Date has to be greater than 0.
- Invalid date "${date}" for month with index "${month}".
AI-assisted analysis of angular/components@0411926e7d (2026-08-31).
Data as JSON: /api/errors/34676940203fd1d1.
Report an issue: GitHub.