{"record":{"id":"4a51f81682a39001","repo":"angular/components","slug":"invalid-date-date-reason-result-invalidr","errorCode":null,"errorMessage":"Invalid date \"${date}\". Reason: \"${result.invalidReason}\".","messagePattern":"Invalid date \"(.+?)\"\\. Reason: \"(.+?)\"\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/material-luxon-adapter/adapter/luxon-date-adapter.ts","lineNumber":160,"sourceCode":"\n  createDate(year: number, month: number, date: number): LuxonDateTime {\n    const options = this._getOptions();\n\n    if (month < 0 || month > 11) {\n      throw Error(`Invalid month index \"${month}\". Month index has to be between 0 and 11.`);\n    }\n\n    if (date < 1) {\n      throw Error(`Invalid date \"${date}\". Date has to be greater than 0.`);\n    }\n\n    // Luxon uses 1-indexed months so we need to add one to the month.\n    const result = this._useUTC\n      ? LuxonDateTime.utc(year, month + 1, date, options)\n      : LuxonDateTime.local(year, month + 1, date, options);\n\n    if (!this.isValid(result)) {\n      throw Error(`Invalid date \"${date}\". Reason: \"${result.invalidReason}\".`);\n    }\n\n    return result;\n  }\n\n  today(): LuxonDateTime {\n    const options = this._getOptions();\n\n    return this._useUTC ? LuxonDateTime.utc(options) : LuxonDateTime.local(options);\n  }\n\n  parse(value: unknown, parseFormat: string | string[]): LuxonDateTime | null {\n    const options: LuxonDateTimeOptions = this._getOptions();\n\n    if (typeof value == 'string' && value.length > 0) {\n      const iso8601Date = LuxonDateTime.fromISO(value, options);\n\n      if (this.isValid(iso8601Date)) {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material-luxon-adapter/adapter/luxon-date-adapter.ts#L142-L178","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst d = adapter.createDate(NaN, 5, 20); // throws with invalidReason\n\n// after\nif (Number.isFinite(year) && year >= 1 && year <= 9999) {\n  const d = adapter.createDate(year, 5, 20);\n}","handlingStrategy":"validation","validationCode":"function safeCreateDate(adapter: DateAdapter<LuxonDateTime>, y: number, m: number, d: number) {\n  if (![y, m, d].every(v => Number.isFinite(v))) return null;\n  if (y < 1 || y > 9999) return null;\n  const result = adapter.createDate(y, m, d);\n  return adapter.isValid(result) ? result : null;\n}","typeGuard":"function isFiniteDateParts(y: unknown, m: unknown, d: unknown): boolean {\n  return [y, m, d].every(v => typeof v === 'number' && Number.isFinite(v));\n}","tryCatchPattern":"try {\n  return adapter.createDate(y, m, d);\n} catch (e) {\n  const reason = /Reason: \"([^\"]+)\"/.exec(String(e.message))?.[1];\n  console.error(`createDate failed: ${reason ?? e.message}`);\n  return null;\n}","preventionTips":["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."],"tags":["angular-material","luxon","invalid-date","validation"],"backgroundTag":"invalid-date-reason","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}