oz / tz

🌐 A time zone helper
GNU General Public License v3.0
849 stars 33 forks source link

feature: tz list with country names #30

Closed chetan closed 10 months ago

chetan commented 2 years ago

This PR adds a --list flag which displays a complete listing of timezones with offsets and country names.

Screen Shot 2022-08-02 at 10 03 59 AM
oz commented 2 years ago

Thanks for contributing this! I'm looking at it right now.

Could you detail how you obtained the gzip-ed JSON file (embedded rawData), and what is its license?

chetan commented 2 years ago

Sorry, meant to include the url in a comment. I believe the json is from here but will need to confirm later when I get back to my computer -

https://github.com/karunais13/country-timezone-list

MIT licensed package

oz commented 2 years ago

I've worked out a way to list zones without parsing JSON, using the system's tz database. It's more for search than listing though.

Would that work for you too?

chetan commented 2 years ago

The go-timezone library simply embeds most of the data as go structs instead of JSON or similar. The purpose of adding the extra json file here is simply to get the additional country name information as the actual timezone names are often not enough to locate the correct zone. For example, if I know a colleague is in Chile, but not their city, I can find it like so:

Screen Shot 2022-08-25 at 9 15 28 AM

Any concerns with the JSON parsing in particular? Perhaps we can convert it to a struct as well to make things safer (and faster)? We can likely also drop the need for the go-timezone package and use only the one source to reduce size if that's a concern. Both speed and size looked ok to me so I didn't spend much time looking at that.

oz commented 2 years ago

The go-timezone library simply embeds most of the data as go structs instead of JSON or similar. The purpose of adding the extra json file here is simply to get the additional country name information as the actual timezone names are often not enough to locate the correct zone.

In the case of Chile, filtering on the zone names still yields usable information:

  CLT (-04:00) :: Chile/Continental
 EAST (-06:00) :: Chile/EasterIsland

But, if you try to find "Italy", or "France" then you're out of luck.

I think that using external JSON data could be a nice UX improvement. Thanks for making the case more clear. 👍🏻

Any concerns with the JSON parsing in particular? Perhaps we can convert it to a struct as well to make things safer (and faster)?

It seems wasteful to parse an entire JSON file each time yes. Do you think we could use go generate to download the file instead, and generate a list of structs before building?

oz commented 10 months ago

A similar feature has been added in 0.6.2 so I'll close this meanwhile. Thanks for the PR! :)