Bash 5.0 printf TZ ambiguous DST transition handling remains undefined
0 reputation · 04 Jan 2023, 04:34 UTC
0 reputation · 04 Jan 2023, 04:34 UTC
The goal is to generate reproducible date strings from epoch values using Bash’s printf with the %T format, while respecting the time zone specified via TZ. In practice, ambiguous times that occur during daylight‑saving transitions (e.g., 2026‑03‑27 02:30 in Europe/Paris) can be interpreted as either the earlier or the later offset. Bash 5.0 relies on the host’s tzdata database, but the language standard does not dictate how to resolve such ambiguities.
Older Bash releases (≤4.3) ignore TZ for this format, falling back to the system default, which can lead to inconsistent outputs across platforms. Because tzdata is updated independently, the same script may produce different results on systems with different database versions.
We need to understand the current behavior and whether a deterministic strategy exists for Bash’s date formatting during DST transitions.
TZ is set?35275 reputation · 04 Jan 2023, 14:08 UTC
Bash 5.0 does not implement its own logic for resolving Daylight Saving Time (DST) ambiguities. Instead, it delegates date formatting via printf %(...)T to the host system's C library (libc) using the strftime() function. Because Bash passes an absolute epoch value (seconds since 1970-01-01 00:00:00 UTC) to the system call, the output is deterministic for a specific environment, even if the resulting local wall-clock time is ambiguous.
Ambiguity in DST transitions typically occurs when converting a local time back to an epoch (e.g., deciding if 02:30 AM occurs before or after a clock shift). However, printf %T operates in the opposite direction: Epoch → Local Time. Since an epoch value represents a unique point in linear time, there is no ambiguity for the system to resolve; it simply applies the offset defined by the current tzdata and libc implementation for that specific moment.
The perceived "undefined" behavior usually stems from two external variables rather than Bash itself:
TZ strings or edge-case transitions differently.printf output.To verify how your specific environment resolves a transition, use a known epoch value during a shift (e.g., Europe/Paris transition). Run the following scoped commands:
# Example: Test a specific epoch with a defined TZ
TZ="Europe/Paris" printf "%(%Y-%m-%d %H:%M:%S)T\n" 1742948400
# Check the system's tzdata version to correlate results
zdump -v Europe/Paris | tail -n 20
To provide a more precise mapping of the behavior you are seeing, please specify the Operating System and libc version (e.g., Ubuntu 22.04 with glibc 2.35), as this is the primary driver of the formatting logic.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.