#21859: fix(logs): respect TZ env var for timestamp display, fix Windows timezone
docs
cli
size: S
Cluster:
Timezone Support Enhancements
## Summary
`openclaw logs` always displayed UTC timestamps regardless of the `TZ` environment variable. On Windows especially, Node.js does not reliably read `TZ` to adjust `getHours()` / `getTimezoneOffset()` — the methods used by the old implementation.
## Root Cause
`formatLocalIsoWithOffset()` in `src/logging/timestamps.ts` manually assembled a timestamp using `getHours()`, `getMinutes()`, `getTimezoneOffset()` etc. These methods read the process timezone from the OS — which on Windows does not pick up the `TZ` environment variable set by the user.
## Fix
### 1. `src/logging/timestamps.ts` — rewrite using `Intl.DateTimeFormat`
Replace the old manual approach with `Intl.DateTimeFormat` using an explicit `timeZone` parameter. `Intl` correctly resolves timezone conversions on all platforms including Windows.
- Function now accepts an optional `timeZone` argument, falling back to `process.env.TZ`, then `Intl.DateTimeFormat().resolvedOptions().timeZone`
- Added `parseGmtOffset()` helper to normalize `"GMT+8"` → `"+08:00"` format
### 2. `src/cli/logs-cli.ts` — auto-enable local time when `TZ` is set
```typescript
// Before
const localTime = Boolean(opts.localTime);
// After
const localTime = Boolean(opts.localTime) || Boolean(process.env.TZ);
```
Users who set `TZ=Asia/Shanghai` now see local timestamps automatically without needing `--local-time`.
## Tests
6 tests in `src/logging/timestamps.test.ts`:
| Test | Result |
|---|---|
| UTC → `+00:00` offset | ✅ |
| `Asia/Shanghai` → `+08:00`, correct hour conversion | ✅ |
| `America/New_York` winter (EST) → `-05:00` | ✅ |
| `America/New_York` summer (EDT) → `-04:00` | ✅ |
| Output matches ISO 8601 with offset regex | ✅ |
| Source does NOT contain `getHours`, `getMinutes`, `getTimezoneOffset` | ✅ |
All 43 tests in `src/logging/` pass.
Fixes #21606
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Replaced manual timezone offset calculation with `Intl.DateTimeFormat` to properly respect the `TZ` environment variable on all platforms, especially Windows. The implementation correctly uses `timeZone` parameter in `Intl.DateTimeFormat` which resolves timezone conversions reliably across platforms. The PR also auto-enables local time display when `TZ` is set in the environment.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is a well-tested refactoring that replaces platform-dependent Date methods with the standard `Intl.DateTimeFormat` API. All 6 new tests pass including timezone conversion validation, DST handling, and verification that legacy methods are no longer used. The change is backward compatible (optional parameter) and addresses a real cross-platform bug on Windows.
- No files require special attention
<sub>Last reviewed commit: b39bb3a</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#19611: fix: use local timezone in log file and console timestamps
by tag-assistant · 2026-02-18
85.6%
#14709: fix: display local timezone in console logs
by Daiyimo · 2026-02-12
85.3%
#12358: fix: Sessions format timestamps in sessions_history using userTimezone
by xialonglee · 2026-02-09
79.3%
#7919: feat: implement timezone support for console timestamps and add ver...
by southpy · 2026-02-03
79.2%
#15784: fix: timestamp parsing should convert seconds to milliseconds
by murasame-desu-ai · 2026-02-13
74.9%
#20915: feat: add configurable timezone support for console log timestamps.
by GauravKrv · 2026-02-19
74.8%
#15754: fix: handle Unix timestamps in seconds in parseAbsoluteTimeMs
by MisterGuy420 · 2026-02-13
73.7%
#11305: fix(logging): remove redundant subsystem prefix from log output
by janckerchen · 2026-02-07
73.2%
#4901: Show timezone abbreviation in system prompt
by dpalfox · 2026-01-30
72.5%
#16542: fix(sessions): use atomic temp+rename write on Windows
by aldoeliacim · 2026-02-14
72.4%