louislam/dockge · error · Error
Invalid timezone:
Error message
Invalid timezone:
What it means
DockgeServer.checkTimezone validates a timezone string by attempting dayjs.utc(...).tz(timezone); if dayjs throws (unknown timezone for the IANA db, or the utcOffset plugin misuse), it rethrows 'Invalid timezone:<timezone>'. Timezones must be IANA names resolvable by dayjs's timezone plugin.
Source
Thrown at backend/dockge-server.ts:540
/**
* Get the current offset
* @returns {string} Time offset
*/
getTimezoneOffset() {
return dayjs().format("Z");
}
/**
* Throw an error if the timezone is invalid
* @param {string} timezone Timezone to test
* @returns {void}
* @throws The timezone is invalid
*/
checkTimezone(timezone : string) {
try {
dayjs.utc("2013-11-18 11:55").tz(timezone).format();
} catch (e) {
throw new Error("Invalid timezone:" + timezone);
}
}
/**
* Initialize the data directory
*/
initDataDir() {
if (! fs.existsSync(this.config.dataDir)) {
fs.mkdirSync(this.config.dataDir, { recursive: true });
}
// Check if a directory
if (!fs.lstatSync(this.config.dataDir).isDirectory()) {
throw new Error(`Fatal error: ${this.config.dataDir} is not a directory`);
}
// Create data/stacks directory
if (!fs.existsSync(this.stacksDir)) {View on GitHub (pinned to f809ae192b)
Solutions
- Pass a valid IANA timezone name such as 'Europe/Berlin' or 'Asia/Tokyo'
- For fixed offsets, map them to Etc/GMT zones, e.g. UTC+8 -> 'Etc/GMT-8' (inverted sign)
- Trim whitespace from user-supplied timezone strings
- Verify the deployment image includes tzdata (alpine: add tzdata package)
Example fix
// before
checkTimezone("UTC+2");
// after
checkTimezone(Intl.DateTimeFormat().resolvedOptions().timeZone); // e.g. "Europe/Paris" Defensive patterns
Strategy: validation
Validate before calling
function isValidIANATimezone(tz) {
if (typeof tz !== "string" || !tz.trim()) return false;
try { new Intl.DateTimeFormat("en-US", { timeZone: tz }); return true; } catch { return false; }
}
if (!isValidIANATimezone(tz)) tz = "Etc/UTC";
socket.emit("...", { timezone: tz }); Type guard
function isTimezone(v: unknown): v is string { return typeof v === "string" && (() => { try { new Intl.DateTimeFormat("en-US", { timeZone: v }); return true; } catch { return false; } })(); } Try / catch
try { server.getTimezone(tz); } catch (e) { if (String(e.message).startsWith("Invalid timezone")) { return "Etc/UTC"; } throw e; } Prevention
- Use Intl.DateTimeFormat().resolvedOptions().timeZone on the client instead of locale strings
- Map fixed offsets (UTC+8) to Etc/GMT zones, remembering the sign inversion
- Ensure the Docker image includes tzdata
- Trim and canonicalize user-supplied timezone inputs
When it happens
Trigger: Calling getTimezone/checkTimezone with e.g. 'UTC+2', 'GMT-5', 'CET', an empty string, or a misspelled IANA name like 'Europe/Berlin ' with trailing space.
Common situations: Client sends a browser locale string instead of an IANA zone; fixed-offset strings like UTC+8 that are not IANA names; server missing timezone data so even valid names throw; dayjs timezone plugin not properly extended in a custom build.
Related errors
- Name must be a string
- Stack name must be a string
- Stack name and service name must be strings
- Invalid stackName or serviceName
- Compose YAML must be a string
AI-assisted analysis of louislam/dockge@f809ae192b (2026-08-31).
Data as JSON: /api/errors/bd4c88c342f5abbf.
Report an issue: GitHub.