Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ LOCATOR=FN20
TZ=America/New_York
```

> **`TZ` is optional** — if omitted, each visitor's browser timezone is used for
> the local-time display. Setting it is still recommended so that server-side
> timestamps (logs, cache TTLs, etc.) match your local time.

Restart to apply:

```bash
Expand Down
19 changes: 17 additions & 2 deletions server/routes/config-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,23 @@ module.exports = function (app, ctx) {
// Whether config is incomplete (show setup wizard)
configIncomplete: CONFIG.callsign === 'N0CALL' || !CONFIG.gridSquare,

// Server timezone (from TZ env var or system)
timezone: process.env.TZ || Intl.DateTimeFormat().resolvedOptions().timeZone || '',
// Server timezone (from TZ env var or system), validated.
// On minimal Linux containers without TZ set, Intl can return "Etc/Unknown"
// which browsers reject with RangeError. Validate before sending.
timezone: (() => {
const tz = process.env.TZ || Intl.DateTimeFormat().resolvedOptions().timeZone || '';
if (!tz) return '';
try {
new Intl.DateTimeFormat(undefined, { timeZone: tz });
return tz;
} catch (e) {
console.warn(
'[config] Invalid resolved timezone "%s" — falling back to empty (client will use browser TZ). Set TZ env var to silence.',
tz,
);
return '';
}
})(),

// Feature availability
features: {
Expand Down
19 changes: 16 additions & 3 deletions src/hooks/app/useTimeState.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,24 @@ export default function useTimeState(configLocation, dxLocation, timezone) {

const utcTime = currentTime.toISOString().substr(11, 8);
const utcDate = currentTime.toISOString().substr(0, 10);
// Validate the timezone once per changed value, not on every render.
// new Intl.DateTimeFormat throws a RangeError for invalid values such as
// "Etc/Unknown" (returned by Node on minimal Linux containers with no TZ set).
const safeTimezone = useMemo(() => {
if (!timezone) return '';
try {
new Intl.DateTimeFormat(undefined, { timeZone: timezone });
return timezone;
} catch {
return '';
}
}, [timezone]);

const localTimeOpts = { hour12: use12Hour };
const localDateOpts = { weekday: 'short', month: 'short', day: 'numeric' };
if (timezone) {
localTimeOpts.timeZone = timezone;
localDateOpts.timeZone = timezone;
if (safeTimezone) {
localTimeOpts.timeZone = safeTimezone;
localDateOpts.timeZone = safeTimezone;
}
const localTime = currentTime.toLocaleTimeString('en-US', localTimeOpts);
const localDate = currentTime.toLocaleDateString('en-US', localDateOpts);
Expand Down
Loading