chronotope / chrono-tz

TimeZone implementations for rust-chrono from the IANA database
Other
235 stars 56 forks source link

Make TIMEZONES map public, so that users may iterate over all timezones. #95

Closed siedentop closed 2 years ago

siedentop commented 2 years ago

I could imagine, that this PR is not implemented in the way you'd prefer. I mostly want to get the conversation started and offer one possible implementation.

For a feature, I thought it would be nice to create an auto-correct dictionary for all known timezones.

So, in this PR I am changing static TIMEZONES to pub static TIMEZONES. On the user side, I am simply creating a list off all timezones like this: chrono_tz::TIMEZONES.keys().map(|x| x.to_string()).collect().

Is this something you would be willing to support? Would you prefer a new function that hid the access to TIMEZONES behind a function?


Pinging previous authors of the modified file: @quodlibetor @petrosagg

ritchie46 commented 2 years ago

This might help.

let timezone = "Africa/Asmara";
timezone.parse::<chrono_tz::Tz>()
djc commented 2 years ago

I'm open to having this, but I'd like to have TIMEZONES be renamed to TIME_ZONES (in a separate commit, please).

siedentop commented 2 years ago

@djc like this, or renaming it everywhere? pub use timezones::TIMEZONES as TIME_ZONES;

EDIT: I just did the right thing, and renamed it everywhere.

djc commented 2 years ago

Thanks for the rename! I'm having some second thoughts as this makes phf part of the public API. How about we wrap the phf::Map in a newtype wrapper that exposes a minimal API (maybe just get() and iter() for now)?

siedentop commented 2 years ago

Sorry for the delay. I've just discovered that TZ_VARIANTS is already public and exported.

Here's what I want to do: chrono_tz::TZ_VARIANTS.iter().map(|x| x.to_string())

So, let's close this PR.