Skip to content

[Server] Add configurable timezone for log timestamps - #196

Merged
LarsLaskowski merged 1 commit into
mainfrom
ccr-9ab3e78d-1nz67k
Oct 20, 2026
Merged

LarsLaskowski merged 1 commit into
mainfrom
ccr-9ab3e78d-1nz67k

Conversation

@LarsLaskowski

@LarsLaskowski LarsLaskowski commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Pull Request

📖 Description

openHAB writes log timestamps without a zone offset, in the timezone configured in its Regional Settings. The parser interpreted them in the timezone of the viewer process, so on a host running on UTC with openHAB set to e.g. America/New_York, every timestamp in the UI was shifted by the zone difference (4 hours in the reported case).

This is a feature/fix with no breaking change:

  • New optional setting LOG_TIMEZONE (IANA name). When set, LogLineParser converts timestamps from that zone to UTC via Intl.DateTimeFormat, independent of the process timezone. No new dependency.
    • DST edge cases: an ambiguous fall-back wall time resolves to the earlier instant; a non-existent spring-forward wall time is shifted forward.
    • The resolved offset is cached per wall-clock minute, so the zoned path is as fast as the default path (the uncached Intl conversion was ~7x slower).
  • Unset keeps the previous behavior (process timezone). An unknown zone name logs a warning and falls back instead of failing startup; the name is normalized to its canonical spelling.
  • The effective timezone is logged on startup (Reading log timestamps as …) to make offsets easy to diagnose from the journal.
  • Docs:
    • README: prebuilt release packages are now the recommended installation path (Node.js 22+ only, no npm, no build), new Timezone of log timestamps section, and LOG_TIMEZONE in the configuration table and the env-file example.
    • ARCHITECTURE: replaces the "not configurable today" note with the new behavior.
    • systemd unit: commented-out LOG_TIMEZONE example.

🎫 Issues

Closes #195

👩‍💻 Reviewer Notes

  • Focus: createZonedConverter() in src/server/logLineParser.ts (candidate selection around DST transitions and the per-minute cache).
  • Smoke test: start the built server with TZ=UTC LOG_TIMEZONE=America/New_York against a log containing 2026-10-20 14:22:24.123 [INFO ] [a.b] - hello; /api/bootstrap returns 2026-10-20T18:22:24.123Z, and the UI shows 14:22 in a New York browser. This was verified locally.
  • Users who already work around the issue with TZ=... are unaffected.

📑 Test Plan

  • src/server/logLineParser.test.ts: new LogLineParser timezone handling suite covering the default process-local behavior, the issue Timestamp in LOG different that OS or wall clock time. #195 regression (EDT), standard time and zones east of UTC (Berlin, Kolkata, UTC), ambiguous fall-back times (New York, Berlin), the spring-forward gap, crossing a DST change within one parser (cache refresh), and continuation lines inheriting the zoned timestamp.
  • src/server/config.test.ts: LOG_TIMEZONE default, valid value with spelling normalization, unknown zone fallback, whitespace-only value.
  • src/server/routes.test.ts: config factory updated for the new field.
  • The full suite passes with the process running in UTC, America/New_York, and Europe/Berlin.

✅ Checklist

General

  • I have added unit tests for my changes, per UNIT_TESTS.md.
  • I have run npm test and npm run typecheck locally and they pass.
  • I have updated the project documentation (README, ARCHITECTURE, etc.) to reflect my changes, where applicable.
  • I have read the CONTRIBUTING documentation and followed the project's code style and conventions.

Server-specific (src/server)

  • I have added or updated a module in src/server (tailer, parser, buffer, routes, SSE hub, config, etc.).
  • I have kept src/server/types.ts in sync with src/client/state.ts for any shared payload change (see ARCHITECTURE.md).
  • I have preserved existing server-side bounds and defaults (buffer/SSE limits, poll interval clamps) unless the change explicitly targets them.

⏭ Next Steps

None.

openHAB writes log timestamps without a zone offset in the timezone set in
its Regional Settings. The parser read them in the viewer process's
timezone, so on a host running on UTC with openHAB set to e.g.
America/New_York every timestamp was shifted by the zone difference.

LOG_TIMEZONE (IANA name) makes the parser convert timestamps from that
zone via Intl, independent of the process timezone, including DST
fall-back/spring-forward edge cases and a per-minute offset cache. Unset
keeps the previous behavior; an unknown name warns and falls back. The
effective timezone is logged on startup.

README now recommends the prebuilt release packages (Node.js 22+, no npm
needed) and documents the timezone setting; ARCHITECTURE and the systemd
unit are updated accordingly.

Closes #195

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H4dBTdvvGiQsgGDcxXr91d
@sonarqubecloud

Copy link
Copy Markdown

@LarsLaskowski
LarsLaskowski marked this pull request as ready for review October 20, 2026 17:48
@LarsLaskowski
LarsLaskowski merged commit a22534c into main Oct 20, 2026
10 checks passed
@LarsLaskowski
LarsLaskowski deleted the ccr-9ab3e78d-1nz67k branch October 20, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timestamp in LOG different that OS or wall clock time.

2 participants