racket/time: Ambiguous local time resolution during DST transitions
0 reputation · 07 Sept 2025, 15:02 UTC
0 reputation · 07 Sept 2025, 15:02 UTC
The racket/time module provides utilities for converting between UTC and system-local time. However, the library relies on the underlying operating system's time zone configuration and does not provide a first-class TimeZone object or a mechanism to specify target IANA time zone identifiers within conversion calls.
This creates uncertainty when handling dates that fall within daylight saving time (DST) transitions, specifically during the autumn "fold" where a local time occurs twice. Because the API does not offer an explicit way to resolve these ambiguities or specify a fold/gap preference, the behavior is deferred to the system level.
Given a Racket environment (v8.0+) running on a system with DST enabled:
34775 reputation · 07 Sept 2025, 23:16 UTC
In Racket (v8.0+), the racket/time module does not implement its own time zone logic. Instead, it serves as a wrapper around the host operating system's C library (libc) functions. Consequently, when converting an ambiguous local time (the "autumn fold") back to UTC, the library defers resolution entirely to the underlying OS.
Because there is no explicit "fold" or "gap" parameter in the Racket API, the resulting UTC timestamp depends on the OS implementation of mktime() or its equivalent. While behavior varies by platform, the most common outcomes are:
There is no documented method within racket/time to specify a target IANA time zone or resolve offsets on a per-call basis without modifying the system environment. To ensure consistent date offsets across different regional server configurations, you have two primary options:
current-seconds) and only convert to local time for final display to the user.TZ environment variable before launching the Racket process. This forces the OS to use a specific IANA time zone regardless of the server's physical location.; Example: Launching the process with a specific timezone
; bash: TZ="America/New_York" racket my_app.rkt
To verify how your specific OS handles the fold, you can test a known transition date:
(require racket/time)
; Test a date known to be ambiguous in your target timezone
(date-to-seconds #date("2026-11-01T01:30:00"))
Warning: Avoid attempting to change the TZ environment variable using (setenv ... ) within a running Racket process. This is generally not thread-safe and may result in inconsistent behavior across different parts of the application.
To provide a more specific recommendation, please clarify: Are you targeting a specific OS (e.g., Linux vs. Windows) for your server deployments?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.