tz icon indicating copy to clipboard operation
tz copied to clipboard

feature: tz list with country names

Open chetan opened this issue 3 years ago • 5 comments

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

chetan avatar Aug 02 '22 14:08 chetan

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?

oz avatar Aug 19 '22 20:08 oz

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

chetan avatar Aug 20 '22 13:08 chetan

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?

oz avatar Aug 21 '22 14:08 oz

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.

chetan avatar Aug 25 '22 13:08 chetan

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 avatar Aug 26 '22 22:08 oz

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

oz avatar Jan 10 '24 00:01 oz