{"record":{"id":"6a52cf640e3dac60","repo":"angular/components","slug":"invalid-seconds-seconds-seconds-value-must-b-6a52cf","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":"Error","httpStatus":null,"severity":"error","filePath":"src/material/core/datetime/native-date-adapter.ts","lineNumber":255,"sourceCode":"    return !isNaN(date.getTime());\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 (!inRange(hours, 0, 23)) {\n        throw Error(`Invalid hours \"${hours}\". Hours value must be between 0 and 23.`);\n      }\n\n      if (!inRange(minutes, 0, 59)) {\n        throw Error(`Invalid minutes \"${minutes}\". Minutes value must be between 0 and 59.`);\n      }\n\n      if (!inRange(seconds, 0, 59)) {\n        throw Error(`Invalid seconds \"${seconds}\". Seconds value must be between 0 and 59.`);\n      }\n    }\n\n    const clone = this.clone(target);\n    clone.setHours(hours, minutes, seconds, 0);\n    return clone;\n  }\n\n  override getHours(date: Date): number {\n    return date.getHours();\n  }\n\n  override getMinutes(date: Date): number {\n    return date.getMinutes();\n  }\n\n  override getSeconds(date: Date): number {\n    return date.getSeconds();","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/core/datetime/native-date-adapter.ts#L237-L273","documentation":"setTime validates seconds to the 0-59 range in dev mode; seconds >= 60 would roll into minutes via Date overflow. The adapter rejects them so the cloned Date's components match what the caller requested.","triggerScenarios":"Calling adapter.setTime(target, h, m, seconds) with seconds < 0 or > 59 — e.g. passing a millisecond value as seconds, or epoch remainder math done incorrectly (often via _parseTimeString paths).","commonSituations":"Confusing ms and seconds fields (epoch % 60000 yields up to 59999), free-form time text like '10:20:75', duration sums overflowing the seconds field.","solutions":["Validate inRange(seconds, 0, 59) before calling setTime.","When deriving from epoch ms, take Math.floor(ms/1000) % 60 for seconds.","Use adapter.addCalendarSeconds for duration addition instead of raw values."],"exampleFix":"// before\nconst secs = ts % 60000; // ms remainder, can be 59999\nadapter.setTime(target, h, m, secs);\n// after\nconst secs = Math.floor(ts / 1000) % 60;\nadapter.setTime(target, h, m, secs);","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(seconds) || seconds < 0 || seconds > 59) {\n  throw new RangeError(`seconds must be 0-59, got ${seconds}`);\n}\nadapter.setTime(target, hours, minutes, seconds);","typeGuard":"function isValidSeconds(s: unknown): s is number {\n  return typeof s === 'number' && Number.isInteger(s) && s >= 0 && s <= 59;\n}","tryCatchPattern":"try {\n  adapter.setTime(target, h, m, seconds);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Invalid seconds')) {\n    const carry = Math.floor(seconds / 60);\n    adapter.setTime(target, h, m + carry, seconds % 60);\n  } else { throw e; }\n}","preventionTips":["Distinguish milliseconds from seconds when deriving time from epochs.","Use Math.floor(ms/1000) % 60 for the seconds component.","Validate parsed time strings component-by-component before setTime."],"tags":["angular-material","date-adapter","time-validation","seconds"],"backgroundTag":"invalid-time-value","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}