angular/components · error · Error
Invalid date "${date}". Reason: "${result.invalidReason}".
Error message
Invalid date "${date}". Reason: "${result.invalidReason}". What it means
After building the Luxon DateTime in createDate, the adapter validates the result. If Luxon considers it invalid (e.g. year out of Luxon's supported range, or parameters that overflow with invalidOverflow handling disabled via options), it throws with Luxon's own invalidReason. This catches cases the earlier month/day range checks cannot, such as invalid year values or internal option misconfiguration.
Source
Thrown at src/material-luxon-adapter/adapter/luxon-date-adapter.ts:160
createDate(year: number, month: number, date: number): LuxonDateTime {
const options = this._getOptions();
if (month < 0 || month > 11) {
throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
}
if (date < 1) {
throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
}
// Luxon uses 1-indexed months so we need to add one to the month.
const result = this._useUTC
? LuxonDateTime.utc(year, month + 1, date, options)
: LuxonDateTime.local(year, month + 1, date, options);
if (!this.isValid(result)) {
throw Error(`Invalid date "${date}". Reason: "${result.invalidReason}".`);
}
return result;
}
today(): LuxonDateTime {
const options = this._getOptions();
return this._useUTC ? LuxonDateTime.utc(options) : LuxonDateTime.local(options);
}
parse(value: unknown, parseFormat: string | string[]): LuxonDateTime | null {
const options: LuxonDateTimeOptions = this._getOptions();
if (typeof value == 'string' && value.length > 0) {
const iso8601Date = LuxonDateTime.fromISO(value, options);
if (this.isValid(iso8601Date)) {View on GitHub (pinned to 0411926e7d)
Solutions
- Validate all inputs are finite numbers before calling createDate (Number.isFinite checks).
- Check the year is within a sane range (e.g. 1–9999) for your app.
- Inspect `result.invalidReason` from the error message — it names the exact Luxon failure (e.g. 'unparsable', 'invalid zone').
- Verify the adapter's options (locale/zone) configured via MAT_LUXON_DATE_ADAPTER_OPTIONS are valid.
Example fix
// before
const d = adapter.createDate(NaN, 5, 20); // throws with invalidReason
// after
if (Number.isFinite(year) && year >= 1 && year <= 9999) {
const d = adapter.createDate(year, 5, 20);
} Defensive patterns
Strategy: validation
Validate before calling
function safeCreateDate(adapter: DateAdapter<LuxonDateTime>, y: number, m: number, d: number) {
if (![y, m, d].every(v => Number.isFinite(v))) return null;
if (y < 1 || y > 9999) return null;
const result = adapter.createDate(y, m, d);
return adapter.isValid(result) ? result : null;
} Type guard
function isFiniteDateParts(y: unknown, m: unknown, d: unknown): boolean {
return [y, m, d].every(v => typeof v === 'number' && Number.isFinite(v));
} Try / catch
try {
return adapter.createDate(y, m, d);
} catch (e) {
const reason = /Reason: "([^"]+)"/.exec(String(e.message))?.[1];
console.error(`createDate failed: ${reason ?? e.message}`);
return null;
} Prevention
- Check Number.isFinite on all date parts to reject NaN/undefined early.
- Keep years within 1–9999 for application data.
- Read the invalidReason in the message to diagnose Luxon-specific failures.
- Validate MAT_LUXON_DATE_ADAPTER_OPTIONS (locale, zone) at startup.
When it happens
Trigger: Calling `adapter.createDate(year, month, date)` where the resulting LuxonDateTime is invalid — typically year outside Luxon's supported range (roughly ±275,760 years), NaN parameters, or an invalid locale/zone in _getOptions() causing the constructor to fail.
Common situations: Passing NaN or undefined year/month/day that slipped past the numeric comparisons; extreme years from data corruption or bad parsing; configuring an invalid zoneCode in the adapter options so DateTime.utc/local yields an invalid zone error.
Related errors
- LuxonDateAdapter: Cannot format invalid date.
- Invalid month index "${month}". Month index has to be betwee
- Invalid date "${date}". Date has to be greater than 0.
- Formats array must not be empty.
- Invalid minutes "${minutes}". Minutes value must be between
AI-assisted analysis of angular/components@0411926e7d (2026-08-31).
Data as JSON: /api/errors/4a51f81682a39001.
Report an issue: GitHub.