Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a list of linked zones for a country #60

dabrorius opened this issue Nov 2, 2016 · 2 comments

Getting a list of linked zones for a country #60

dabrorius opened this issue Nov 2, 2016 · 2 comments


Copy link

dabrorius commented Nov 2, 2016

Hi, recently we switched to using tzinfo with tzinfo-data gem which led to some weird issues.
When I try to get time zones for Croatia I get only Europe/Belgrade

pry(main)> TZInfo::Country.get('HR').zones
=> [#<TZInfo::TimezoneProxy: Europe/Belgrade>]

However, without using tzinfo-data I get the correct time zone, which is Europe/Zagreb

[3] pry(main)> TZInfo::Country.get('HR').zones           
=> [#<TZInfo::TimezoneProxy: Europe/Zagreb>]

This might the intended behaviour, because in IANA database Europe/Zagreb is linked to Europe/Belgrade, however we need to list the original time zone name when letting the user select the time zone.

So my question is, is there a way to list original names of the time zones for a country, instead of jumping to the linked ones?

Copy link

philr commented Nov 2, 2016

What you are seeing is the intended behaviour. It is actually caused by the definitions in the IANA Time Zone Database, not because tzinfo is jumping through linked zones.

The Country#zones method returns data from one of either the or files in the IANA Time Zone Database. was deprecated in 2014 and replaced by

The file was introduced as a simplification to the database. It only lists distinct non-linked time zones that have differences since 1970. For Croatia, this means that the correct time zone as defined by the IANA Time Zone Database maintainers in is Europe/Belgrade (even though Belgrade is in Serbia).

The file does still list the linked zone Europe/Zagreb as the time zone for Croatia.

The tzinfo-data gem includes just the data from When using your system time zone data instead of tzinfo-data, tzinfo will try and use the file if it exists and will fallback to

I suspect that your system doesn't include the newer file. When you're not using tzinfo-data, tzinfo is having to fall back to and you see Europe/Zagreb instead of Europe/Belgrade.

The intention of the IANA Time Zone Database coordinator appears to be to stop distributing at some point. It is therefore not really sensible to include a way of accessing the data through tzinfo-data.

When using tzinfo-data, it is possible to query the list of zones that link to a particular zone. For example, the following would return you all the zones that link to Europe/Belgrade:

TZInfo::Timezone.all_linked_zones.find_all do |z|
  z.canonical_zone.identifier == 'Europe/Belgrade'

However, you would need to use a separate source of data to determine which country the identifiers of the returned zones relate to.

It sounds like you are having users select a time zone by country and then zone identifier. If this is the case then, for countries that only have a single time zone (like Croatia), I'd suggest not showing a list of zone identifiers and automatically selecting the only available option.

Copy link

dabrorius commented Nov 4, 2016

Thanks again for a detailed response, it seems we're just going to go with the new standard and be over with it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants