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
setTime validates seconds to the 0-59 range in dev mode; seconds >= 60 would roll into minutes via Date overflow. The adapter rejects them so the cloned Date's components match what the caller requested.
Source
Thrown at src/material/core/datetime/native-date-adapter.ts:255
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();
}
override getSeconds(date: Date): number {
return date.getSeconds();View on GitHub (pinned to 0411926e7d)
Solutions
- Validate inRange(seconds, 0, 59) before calling setTime.
- When deriving from epoch ms, take Math.floor(ms/1000) % 60 for seconds.
- Use adapter.addCalendarSeconds for duration addition instead of raw values.
Example fix
// before const secs = ts % 60000; // ms remainder, can be 59999 adapter.setTime(target, h, m, secs); // after const secs = Math.floor(ts / 1000) % 60; adapter.setTime(target, h, m, secs);
Defensive patterns
Strategy: validation
Validate before calling
if (!Number.isInteger(seconds) || seconds < 0 || seconds > 59) {
throw new RangeError(`seconds must be 0-59, got ${seconds}`);
}
adapter.setTime(target, hours, minutes, 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(target, h, m, seconds);
} catch (e) {
if (e instanceof Error && e.message.includes('Invalid seconds')) {
const carry = Math.floor(seconds / 60);
adapter.setTime(target, h, m + carry, seconds % 60);
} else { throw e; }
} Prevention
- Distinguish milliseconds from seconds when deriving time from epochs.
- Use Math.floor(ms/1000) % 60 for the seconds component.
- Validate parsed time strings component-by-component before setTime.
When it happens
Trigger: Calling adapter.setTime(target, h, m, seconds) with seconds < 0 or > 59 — e.g. passing a millisecond value as seconds, or epoch remainder math done incorrectly (often via _parseTimeString paths).
Common situations: Confusing ms and seconds fields (epoch % 60000 yields up to 59999), free-form time text like '10:20:75', duration sums overflowing the seconds field.
Related errors
- Invalid hours "${hours}". Hours value must be between 0 and
- Invalid minutes "${minutes}". Minutes value must be between
- 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.
AI-assisted analysis of angular/components@0411926e7d (2026-08-31).
Data as JSON: /api/errors/6a52cf640e3dac60.
Report an issue: GitHub.