{"record":{"id":"50a239f27c43e916","repo":"angular/components","slug":"invalid-seconds-seconds-seconds-value-must-b","errorCode":null,"errorMessage":"Invalid seconds \"${seconds}\". Seconds value must be between 0 and 59.","messagePattern":"Invalid seconds \"(.+?)\"\\. Seconds value must be between 0 and 59\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material-date-fns-adapter/adapter/date-fns-adapter.ts","lineNumber":231,"sourceCode":"    return isValid(date);\n  }\n\n  invalid(): Date {\n    return new Date(NaN);\n  }\n\n  override setTime(target: Date, hours: number, minutes: number, seconds: number): Date {\n    if (typeof ngDevMode === 'undefined' || ngDevMode) {\n      if (hours < 0 || hours > 23) {\n        throw Error(`Invalid hours \"${hours}\". Hours value must be between 0 and 23.`);\n      }\n\n      if (minutes < 0 || minutes > 59) {\n        throw Error(`Invalid minutes \"${minutes}\". Minutes value must be between 0 and 59.`);\n      }\n\n      if (seconds < 0 || seconds > 59) {\n        throw Error(`Invalid seconds \"${seconds}\". Seconds value must be between 0 and 59.`);\n      }\n    }\n\n    return set(this.clone(target), {hours, minutes, seconds, milliseconds: 0});\n  }\n\n  override getHours(date: Date): number {\n    return getHours(date);\n  }\n\n  override getMinutes(date: Date): number {\n    return getMinutes(date);\n  }\n\n  override getSeconds(date: Date): number {\n    return getSeconds(date);\n  }\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material-date-fns-adapter/adapter/date-fns-adapter.ts#L213-L249","documentation":"DateFnsAdapter.setTime validates the seconds argument (must be 0–59) and throws in dev mode when out of range, rejecting values that would silently overflow into the next minute.","triggerScenarios":"Calling setTime(target, hours, minutes, seconds) with seconds < 0 or seconds > 59 — e.g. countdown arithmetic producing second = 60, or raw timestamp components (epoch seconds) fed as clock seconds.","commonSituations":"Stopwatch/countdown logic decrementing seconds to -1 or summing past 59; extracting seconds from durations instead of actual clock times; parsing 'mm:ss' strings without bounds checks.","solutions":["Use addCalendarSeconds (or date-fns set with arithmetic) for values that may exceed 59.","Validate inputs to 0–59 before calling setTime.","Convert durations via explicit normalization (carry into minutes) before applying."],"exampleFix":"// before\nthis.adapter.setTime(target, 10, 30, 60); // throws\n// after\nthis.adapter.setTime(this.adapter.addCalendarSeconds(target, 60), 0, 0, 0); // or 10:31:00 via wrap","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(seconds) || seconds < 0 || seconds > 59) {\n  throw new RangeError(`seconds must be 0-59, got ${seconds}`);\n}\nconst d = adapter.setTime(target, hours, minutes, seconds);","typeGuard":"function isValidSecond(s: unknown): s is number {\n  return typeof s === 'number' && Number.isInteger(s) && s >= 0 && s <= 59;\n}","tryCatchPattern":"try {\n  return this.adapter.setTime(t, h, m, s);\n} catch (e) {\n  if ((e as Error).message.startsWith('Invalid seconds')) {\n    return this.adapter.setTime(t, h, m, Math.min(Math.max(s, 0), 59));\n  }\n  throw e;\n}","preventionTips":["Use addCalendarSeconds for countdown/duration values that can exceed 59","Normalize durations (carry seconds into minutes) before setting clock time","Validate extracted clock components before setTime","Distinguish durations from clock times in your date utility layer"],"tags":["date","time","validation","material","date-fns","dev-mode"],"backgroundTag":"invalid-time-component","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}