{"record":{"id":"6e3d84ec2668cf7a","repo":"louislam/uptime-kuma","slug":"invalid-start-date","errorCode":null,"errorMessage":"Invalid start date","messagePattern":"Invalid start date","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/model/maintenance.js","lineNumber":161,"sourceCode":"     * @param {object} obj Data to fill bean with\n     * @returns {Promise<Bean>} Filled bean\n     */\n    static async jsonToBean(bean, obj) {\n        if (obj.id) {\n            bean.id = obj.id;\n        }\n\n        bean.title = obj.title;\n        bean.description = obj.description;\n        bean.strategy = obj.strategy;\n        bean.interval_day = obj.intervalDay;\n        bean.timezone = obj.timezoneOption;\n        bean.active = obj.active;\n\n        if (obj.dateRange[0]) {\n            const parsedDate = new Date(obj.dateRange[0]);\n            if (isNaN(parsedDate.getTime()) || parsedDate.getFullYear() > 9999) {\n                throw new Error(\"Invalid start date\");\n            }\n\n            bean.start_date = obj.dateRange[0];\n        } else {\n            bean.start_date = null;\n        }\n\n        if (obj.dateRange[1]) {\n            const parsedDate = new Date(obj.dateRange[1]);\n            if (isNaN(parsedDate.getTime()) || parsedDate.getFullYear() > 9999) {\n                throw new Error(\"Invalid end date\");\n            }\n\n            bean.end_date = obj.dateRange[1];\n        } else {\n            bean.end_date = null;\n        }\n","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/model/maintenance.js#L143-L179","documentation":"Maintenance.jsonToBean parses obj.dateRange[0] with `new Date(...)` and throws if the result is NaN (unparseable date string) or has a year > 9999 (out-of-range per the storage schema). This guards the start_date column before it is written; the same check on dateRange[1] produces the sibling 'Invalid end date' error.","triggerScenarios":"A maintenance window payload whose dateRange[0] is a malformed string ('2024-13-45', 'asdf', ''), an impossible year (year 10000+), or a format Date cannot parse in this Node version. Commonly sent by a broken frontend date picker or a hand-crafted API request.","commonSituations":"Browser timezone/locale quirks that emit an unparseable string; copy-paste of a date with the wrong locale; automated scripts POSTing ISO strings with offset suffixes the parser rejects; bad migration data.","solutions":["Send dateRange[0] as a valid ISO 8601 string (e.g. '2024-08-12T10:00:00.000Z') — that is what the UI emits.","Validate in the client before submit; if you call the API directly, parse with dayjs/Date first and reject NaN.","Confirm the year is within [1970, 9999] — values beyond 9999 are rejected to fit the SQL DATETIME range.","If migrating historical data, clamp or skip rows with invalid dates instead of forwarding them."],"exampleFix":"// before\nif (obj.dateRange[0]) {\n    const parsedDate = new Date(obj.dateRange[0]);\n    if (isNaN(parsedDate.getTime()) || parsedDate.getFullYear() > 9999) {\n        throw new Error(\"Invalid start date\");\n    }\n    bean.start_date = obj.dateRange[0];\n}\n\n// after — normalise to ISO and report the bad value\nif (obj.dateRange[0]) {\n    const parsedDate = new Date(obj.dateRange[0]);\n    if (isNaN(parsedDate.getTime()) || parsedDate.getFullYear() > 9999) {\n        throw new Error(`Invalid start date: ${JSON.stringify(obj.dateRange[0])}`);\n    }\n    bean.start_date = parsedDate.toISOString();\n}","handlingStrategy":"validation","validationCode":"// Validate a dateRange start before POSTing to the maintenance API\nfunction isValidMaintenanceDate(v) {\n    if (!v) return true; // null/empty is allowed\n    const d = new Date(v);\n    return !isNaN(d.getTime()) && d.getFullYear() <= 9999;\n}","typeGuard":"function isValidMaintenanceDate(v) {\n    if (!v) return true;\n    const d = new Date(v);\n    return !isNaN(d.getTime()) && d.getFullYear() <= 9999;\n}","tryCatchPattern":"try {\n    await Maintenance.jsonToBean(bean, obj);\n} catch (e) {\n    if (/Invalid start date/.test(e.message)) {\n        // surface a field-level error to the UI for dateRange[0]\n    }\n    throw e;\n}","preventionTips":["Always emit ISO 8601 UTC strings from the date pickers.","Reject obviously bad years on the client before submit.","Treat jsonToBean as atomic — do not persist the bean if it throws."],"tags":["maintenance","validation","date"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}