Lua os library and host C time functions: handling ambiguous local times during DST transitions
0 reputation · 30 Oct 2022, 17:55 UTC
When constructing a time table for os.time, the isdst flag can be set to true, false, or omitted to indicate daylight‑saving status for the given local time.
The Lua reference manual does not define what happens when the supplied local time is ambiguous (e.g., 1:30 am during a “fall back” transition) or skipped (e.g., 2:30 am during a “spring forward” jump), leaving the normalization to the underlying C library’s mktime.
Because mktime’s behavior varies across platforms—glibc, macOS libc, Windows CRT—the same os.time call may produce different timestamps, affecting any code that relies on exact UTC conversion or protocol timestamps.
What does os.time return when isdst is explicitly set for an ambiguous or skipped local time? Does the result differ between major C library implementations? Is there a portable way, using only the Lua standard library, to detect or resolve such ambiguity?