time icon indicating copy to clipboard operation
time copied to clipboard

tzdb support

Open jhpratt opened this issue 5 years ago • 12 comments

This is a general tracking issue for all support related to the IANA Time Zone database.

At some point in the future, my hope is to have full support for the tzdb via a ZonedDateTime struct and a Period type.

General inspiration could come from C++20's proposed API for timezones [ref]. It should be possible to build a static/const singleton by using a build script.

jhpratt avatar Dec 04 '19 16:12 jhpratt

The tzfile crate was recently brought to my attention and may be a decent starting point once I get around to implementing this.

jhpratt avatar Nov 01 '21 22:11 jhpratt

I've just begun implementing support for tz database without relying on chrono dependency.

EDIT: link to repository for anyone interested: https://github.com/Yuri6037/time-tz

Yuri6037 avatar Feb 07 '22 17:02 Yuri6037

Quick update: I've just finished initial version with support for timezone conversions: https://crates.io/crates/time-tz

Yuri6037 avatar Feb 07 '22 23:02 Yuri6037

Thank you! It's by no means the kind of API that I've envisioned, but having something will hopefully be helpful to others until I get around to this — whenever that may be.

jhpratt avatar Feb 07 '22 23:02 jhpratt

This is not yet finished. I don't plan to leave the API as it is forever. The reason why it's done this way is because parsing the tz info and setting up the actual lookup code was more complicated than I've anticipated.

My plan is to have an API similar to chrono-tz to quickly access the various timezones.

If anyone needs features that are not currently supported by time-tz feel free to open issues on the GitHub.

Yuri6037 avatar Feb 07 '22 23:02 Yuri6037

The reason why it's done this way is because parsing the tz info and setting up the actual lookup code was more complicated than I've anticipated.

That's why this issue is E-hard 🙂 I look forward to seeing what you are able to do.

jhpratt avatar Feb 08 '22 00:02 jhpratt

Just a quick update: I've finally finished API v2 which now allows to very quickly re-implement localtime:

    let system_tz = time_tz::system::get_timezone()
        .expect("Failed to find system timezone");
    let localtime = OffsetDateTime::now_utc().to_timezone(system_tz);
    // the system timezone name in IANA format is in system_tz.name() now

Yuri6037 avatar Feb 12 '22 13:02 Yuri6037

Something to keep an eye on/draw inspiration from is https://github.com/unicode-org/icu4x/issues/1003 which is the tracking issue for ZonedDateTime in icu4x. It draws inspiration from the TC39 Temporal standard which I've personally come to like very much!

LinusU avatar Oct 19 '22 23:10 LinusU

Thanks @LinusU! I am aware of temporal, but I'll definitely check out that issue.

jhpratt avatar Oct 19 '22 23:10 jhpratt

@Yuri6037 thank you for the crate dude, it's awesome!

olekspickle avatar Jun 20 '23 15:06 olekspickle