{"record":{"id":"7310675712d659ab","repo":"louislam/uptime-kuma","slug":"invalid-timezone-timezone","errorCode":null,"errorMessage":"Invalid timezone:${timezone}","messagePattern":"Invalid timezone:(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/uptime-kuma-server.js","lineNumber":465,"sourceCode":"    /**\n     * Get the current offset\n     * @returns {string} Time offset\n     */\n    getTimezoneOffset() {\n        return dayjs().format(\"Z\");\n    }\n\n    /**\n     * Throw an error if the timezone is invalid\n     * @param {string} timezone Timezone to test\n     * @returns {void}\n     * @throws The timezone is invalid\n     */\n    checkTimezone(timezone) {\n        try {\n            dayjs.utc(\"2013-11-18 11:55\").tz(timezone).format();\n        } catch (e) {\n            throw new Error(\"Invalid timezone:\" + timezone);\n        }\n    }\n\n    /**\n     * Set the current server timezone and environment variables\n     * @param {string} timezone Timezone to set\n     * @returns {Promise<void>}\n     */\n    async setTimezone(timezone) {\n        this.checkTimezone(timezone);\n        await Settings.set(\"serverTimezone\", timezone, \"general\");\n        process.env.TZ = timezone;\n        dayjs.tz.setDefault(timezone);\n    }\n\n    /**\n     * TODO: Listen logic should be moved to here\n     * @returns {Promise<void>}","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/uptime-kuma-server.js#L447-L483","documentation":"Thrown by UptimeKumaServer.checkTimezone(timezone) when `dayjs.utc(\"2013-11-18 11:55\").tz(timezone).format()` raises an exception — i.e. the timezone string is not a valid IANA zone identifier recognized by the dayjs timezone plugin. The probe date is arbitrary; only the tz() lookup matters.","triggerScenarios":"setTimezone(timezone) (uptime-kuma-server.js:474) called from server.js:1527 (settings save, data.serverTimezone) or general-socket-handler.js:50 with an invalid timezone — e.g. \"Foo/Bar\", \"GMT+2\", \"EST\", a typo like \"Amercia/New_York\", or a bare offset string. getTimezone() also calls checkTimezone for process.env.TZ, settings, and the dayjs guess, but it wraps each call in try/catch with fallback, so only setTimezone propagates this error to the socket layer.","commonSituations":"Operator sets TZ env var to a non-IANA value at deploy time; user types a free-form timezone in the settings UI; settings.serverTimezone corrupted in the DB after a manual edit; running on a minimal container whose /usr/share/zoneinfo is stripped, causing otherwise-valid zones to be rejected.","solutions":["Use a full IANA timezone identifier from the tz database (e.g. \"America/New_York\", \"Europe/Berlin\", \"UTC\").","Populate the timezone picker from Intl.supportedValuesOf('timeZone') or a tz list rather than free text.","In containers, install the tzdata package so dayjs can resolve zones.","When setting TZ at boot, prefer getTimezone()'s fallback behavior by leaving it unset rather than forcing an invalid value."],"exampleFix":"// before\nprocess.env.TZ = \"GMT+2\";        // not an IANA zone\nawait server.setTimezone(\"EST\");   // ambiguous abbreviation\n\n// after\nprocess.env.TZ = \"Europe/Berlin\";\nawait server.setTimezone(\"America/New_York\");\n// verify quickly:\ntry { new Intl.DateTimeFormat(\"en\", { timeZone: tz }); } catch { /* invalid */ }","handlingStrategy":"validation","validationCode":"function isValidTimezone(tz) {\n  try { new Intl.DateTimeFormat(\"en-US\", { timeZone: tz }); return true; } catch { return false; }\n}\nif (!isValidTimezone(tz)) throw new Error(\"Invalid timezone\");","typeGuard":"const isIanaTimezone = (v) => typeof v === \"string\" && isValidTimezone(v);","tryCatchPattern":"try { server.checkTimezone(tz); } catch (e) { if (/Invalid timezone/.test(e.message)) tz = \"UTC\"; /* fallback */ }","preventionTips":["Always use full IANA identifiers (Europe/Berlin, America/New_York, UTC).","Populate the picker from Intl.supportedValuesOf('timeZone').","In containers, install tzdata so zones resolve."],"tags":["timezone","dayjs","settings","validation","uptime-kuma"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}