Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support getting timezone offset in Emscripten #257

Open
curiousdannii opened this issue Feb 11, 2025 · 2 comments
Open

Support getting timezone offset in Emscripten #257

curiousdannii opened this issue Feb 11, 2025 · 2 comments
Labels
question Further information is requested

Comments

@curiousdannii
Copy link

curiousdannii commented Feb 11, 2025

Emscripten supports getting the timezone offset (via libc like this: https://stackoverflow.com/a/13804869/2854284). While not as reliable as using the full TZ DB, it would allow at least many basic TZ functions to work in Emscripten builds.

What about adding a system_fixed function that just returns a timezone offset, and supporting it in Emscripten? A separate function is better so that people only use it if the main system function isn't supported on their platform.

(It would also be possible to support calling JS functions to return the offset directly, but without an EM_JS macro in Rust it wouldn't be seamless for end users, they'd have to manually link a JS file.) (I tried making an EM_JS macro but it was way beyond me!)

@BurntSushi BurntSushi added the question Further information is requested label Feb 11, 2025
@BurntSushi
Copy link
Owner

Yeah, so as I said on reddit, this probably isn't going to happen. Making a paved path for returning just a system offset kinda goes right against the core of Jiff philosophy. You can of course get the offset yourself and make a TimeZone::fixed, but I don't think I want to bless that approach. Even with a separate routine. The reason why it's broken is because many time zones (i.e., ones with DST) cannot be expressed by a single offset. And so the time zone returned in this case would likely lead to incorrect arithmetic and/or formatting. It's just a bad experience overall.

I think for me to accept something like, it would need to be a pragmatic trade-off that acknowledges a huge number of people constantly running into this as a problem. So I'll leave this issue open for a bit, but my impression is that this isn't something a lot of folks are hitting.

Note that if you can set an environment variable, like TZ, and make Jiff see it, then you could set it to a POSIX time zone like EST5EDT,M3.2.0,M11.1.0 and Jiff would pick that up. Or just make a TimeZone::posix from a string embedded in your program. I'm guessing this doesn't work for your use case, but I thought it was worth mentioning.

@curiousdannii
Copy link
Author

Yeah that's fair. Just unfortunate that we can't do more for Emscripten. Maybe once the Temporal API is widely supported there might be a way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants