Repository navigation
Add POSIX TZ support for WASI - #930
abelgeorgeantony wants to merge 2 commits into
Conversation
|
Thanks! I'm not very familiar with either timezones or musl's implementation of timezones. My naive expectation here is that this PR would remove a bunch of Could you explain a bit more why that's the case? Why isn't upstream musl code used mostly-as-is, and why is a large amount of new code introduced here? |
|
I went with a separate WASI implementation because of the filesystem dependencies in upstream musl's implementation. It can search for and load TZif files from locations such as There were also WASI-specific differences to account for, such as the I hadn't fully explored whether the POSIX parsing and transition logic could be separated cleanly from TZif handling. I agree that reusing musl's existing implementation would be preferable, and I'd be happy to explore that approach. |
|
I think it's reasonable to skip probes for unix-like files because yeah they're practically guarnateed to not exist in the sandbox. That being said if upstream code could be reused as-is as much as possible I'd prefer that. For example an |
Add POSIX
TZstring support to the WASI-specific timezone implementation.Previously, the WASI-specific implementation provided only UTC timezone information. This adds support for configuring timezones through POSIX
TZstrings.The implementation supports:
Jn,n, andMm.n.dformats.tzname,timezone,daylight, andtzset(), under the appropriate feature-test macros.It also enables
%Zparsing instrptime.The existing upstream TZif implementation and WASI internal ABI are preserved.
When daylight-saving rules are omitted, the implementation uses current U.S. transition rules as its implementation-defined default. This change does not add geographical IANA timezone database support or TZif file loading.
Testing
TZ=UTC-5:30correctly produces an offset of 330 minutes east of UTC.Motivation
This change was motivated by an issue encountered while running Haskell applications under WASI. GHC's
Data.Time.LocalTime.getCurrentTimeZonerelies on the underlying C library's local-time support to determine the configured timezone. However, the WASI-specific timezone implementation effectively treated the local timezone as UTC and did not interpret POSIXTZspecifications.Consequently, setting
TZ=UTC-5:30did not produce the expected UTC+05:30 offset. Supporting POSIXTZstrings addresses this limitation at the libc level, allowing applications and language runtimes to obtain the configured local timezone without implementing their own timezone handling.AI disclosure
AI assistance (ChatGPT) was used during analysis and implementation, CI failure investigation, and preparation of this pull request description. I reviewed the changes and verified them through local testing and GitHub Actions.