{"record":{"id":"835218cb61e9af6c","repo":"angular/components","slug":"invalid-date-date-date-has-to-be-greater-tha-835218","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":"Error","httpStatus":null,"severity":"error","filePath":"src/material/core/datetime/native-date-adapter.ts","lineNumber":137,"sourceCode":"    return this.getDate(\n      this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0),\n    );\n  }\n\n  clone(date: Date): Date {\n    return new Date(date.getTime());\n  }\n\n  createDate(year: number, month: number, date: number): Date {\n    if (typeof ngDevMode === 'undefined' || ngDevMode) {\n      // Check for invalid month and date (except upper bound on date which we have to check after\n      // creating the Date).\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\n    let result = this._createDateWithOverflow(year, month, date);\n    // Check that the date wasn't above the upper bound for the month, causing the month to overflow\n    if (result.getMonth() != month && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n      throw Error(`Invalid date \"${date}\" for month with index \"${month}\".`);\n    }\n\n    return result;\n  }\n\n  today(): Date {\n    return new Date();\n  }\n\n  parse(value: any, parseFormat?: any): Date | null {\n    // We have no way using the native JS Date to set the parse format or locale, so we ignore these","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/core/datetime/native-date-adapter.ts#L119-L155","documentation":"NativeDateAdapter.createDate rejects a day-of-month less than 1 in dev mode. Day 0 or negative would silently roll back to the last day of the previous month, so the adapter fails fast instead.","triggerScenarios":"Calling adapter.createDate(year, month, date) with date < 1 — e.g. passing 0 to mean 'last day of previous month' or computing day offsets without clamping.","commonSituations":"Loop code that starts at day 0 to compute month boundaries; deserialized/parsed day values that are 0 or NaN-ish when cast; custom date pickers feeding raw user input.","solutions":["Validate day >= 1 before calling createDate.","Use adapter.getLastDateOfMonth(month, year) or createDate with the correct day to get month boundaries.","Sanitize parsed numeric input (check isNaN and range) before constructing dates."],"exampleFix":"// before\nconst lastDayPrevMonth = adapter.createDate(2026, 4, 0);\n// after\nconst lastDayPrevMonth = adapter.addCalendarDays(adapter.createDate(2026, 4, 1), -1);","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(date) || date < 1) {\n  throw new RangeError(`date must be >= 1, got ${date}`);\n}\nconst d = adapter.createDate(year, month, date);","typeGuard":"function isValidDayOfMonth(d: unknown): d is number {\n  return typeof d === 'number' && Number.isInteger(d) && d >= 1 && d <= 31;\n}","tryCatchPattern":"try {\n  d = adapter.createDate(year, month, date);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Date has to be greater than 0')) {\n    d = adapter.addCalendarDays(adapter.createDate(year, month, 1), date - 1);\n  } else { throw e; }\n}","preventionTips":["Never use day 0 to compute month boundaries; use addCalendarDays from day 1.","Sanitize parsed day inputs for NaN and range before constructing dates.","Write unit tests for boundary days (1st and last of month)."],"tags":["angular-material","date-adapter","date-validation"],"backgroundTag":"invalid-date-value","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}