WebAssembly / wasi-clocks

Clocks API for WASI
37 stars 14 forks source link

Time zone support #25

Closed fluffysquirrels closed 1 year ago

fluffysquirrels commented 1 year ago

I'm working on a project in a WASI context that uses time in local time zones. I see how the API in this proposal would support getting the current time in the UTC time zone, but not in the user's local time zone.

What do you think about adding a new resource that lets the WASI guest fetch the local time zone (e.g. as seconds offset from UTC)? Since the local time zone could be used to fingerprint a user, it makes sense to me to add a resource as a new capability to control access to this.

sunfishcode commented 1 year ago

Does this use case need access to the timezone database, as is being discussed in https://github.com/WebAssembly/WASI/issues/25, or would it be enough to just return the UTC offset?

fluffysquirrels commented 1 year ago

In my use case I just need the offset.

In case it helps, I'm trying to patch the rust crate chrono to work in a WASI-like target, currently using some custom component imports based on the interface in this repo.

fluffysquirrels commented 1 year ago

For completeness, some other prior related issues:

fluffysquirrels commented 1 year ago

I looked more closely at the implementation of chrono. Internally on Unix it uses a timezone database, but as far as I can tell this data is not exposed and for WASI we could have an alternate implementation just using the UTC offset.

sdeleuze commented 1 year ago

On Kotlin side, I am leveraging https://github.com/Kotlin/kotlinx-datetime multi-platform library, which seems to require access to the timezone database, see the platform specific functions here.