{"record":{"id":"57e6784f142594fd","repo":"angular/components","slug":"invalid-date-date-date-has-to-be-greater-tha-57e678","errorCode":null,"errorMessage":"Invalid date \"${date}\". Date has to be greater than 0.","messagePattern":"Invalid date \"(.+?)\"\\. Date has to be greater than 0\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material-luxon-adapter/adapter/luxon-date-adapter.ts","lineNumber":151,"sourceCode":"    return date.daysInMonth!;\n  }\n\n  clone(date: LuxonDateTime): LuxonDateTime {\n    return LuxonDateTime.fromObject(date.toObject(), {\n      ...this._getOptions(),\n      zone: date.zone,\n    });\n  }\n\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);","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material-luxon-adapter/adapter/luxon-date-adapter.ts#L133-L169","documentation":"LuxonDateAdapter.createDate requires the day-of-month argument to be at least 1; day 0 or negative has no valid calendar meaning in this API. The adapter throws this error before constructing the Luxon DateTime so callers get a clear message instead of an invalid result.","triggerScenarios":"Calling `adapter.createDate(year, month, 0)` or a negative day — commonly when day arithmetic (e.g. 'yesterday' as day-1) underflows, or when a 0 default was passed for an unset day.","commonSituations":"Computing previous-month days manually instead of letting the adapter roll over; passing uninitialized variables defaulting to 0; porting code that relied on JS Date's day-0 rollover behavior.","solutions":["Ensure the day argument is >= 1 before calling createDate.","To get the last day of the previous month, construct via the adapter's other APIs or compute with Luxon directly, not with day=0.","Validate user-supplied day input range 1–31 (and check month length via adapter.getNumDaysInMonth).","Initialize day variables to a valid default (e.g. 1) rather than 0."],"exampleFix":"// before\nconst d = adapter.createDate(2024, 2, 0); // throws\n\n// after\nconst lastJan = adapter.createDate(2024, 0, adapter.getNumDaysInMonth(adapter.createDate(2024, 0, 1)));","handlingStrategy":"validation","validationCode":"function safeCreateDate(adapter: DateAdapter<LuxonDateTime>, y: number, m: number, d: number) {\n  if (!Number.isInteger(d) || d < 1 || d > 31) {\n    throw new Error(`day must be 1-31, got ${d}`);\n  }\n  return adapter.createDate(y, m, d);\n}","typeGuard":"function isValidDayOfMonth(d: unknown): d is number {\n  return typeof d === 'number' && Number.isInteger(d) && d >= 1 && d <= 31;\n}","tryCatchPattern":"try {\n  return adapter.createDate(y, m, d);\n} catch (e) {\n  if (String(e.message).startsWith('Invalid date \"') && String(e.message).includes('greater than 0')) return null;\n  throw e;\n}","preventionTips":["Never use day=0 to mean 'last day of previous month'; compute via the adapter APIs.","Initialize day variables to 1, not 0.","Validate user day input before calling createDate.","Prefer adapter.parse over manual y/m/d assembly when input is a string."],"tags":["angular-material","luxon","date-arithmetic","invalid-argument"],"backgroundTag":"invalid-date-day","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}