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

Can't get canonical zone #97

Closed
jablan opened this Issue Jan 16, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@jablan
Copy link

jablan commented Jan 16, 2019

Hi, I'm trying to get a canonical timezone, for example from Europe/Skopje. On my machine i have:

$ ls -l /usr/share/zoneinfo/Europe/Skopje 
lrwxrwxrwx 1 root root 9 Jan  1 06:22 /usr/share/zoneinfo/Europe/Skopje -> Podgorica

but in irb I'm getting:

> TZInfo::Timezone.get("Europe/Skopje").canonical_zone
 => #<TZInfo::DataTimezone: Europe/Skopje> # expecting Podgorica here

The source is ok:

> TZInfo::DataSource.get
 => #<TZInfo::ZoneinfoDataSource: /usr/share/zoneinfo> 

Am I doing something wrong?

@philr

This comment has been minimized.

Copy link
Member

philr commented Jan 16, 2019

The canonical_zone and canonical_identifier methods only return meaningful results when used with RubyDataSource (and the tzinfo-data gem):

TZInfo::DataSource.get
# => #<TZInfo::DataSources::RubyDataSource: tzdb v2018i, tzinfo-data v1.2018.9>
TZInfo::Timezone.get("Europe/Skopje").canonical_zone
# => #<TZInfo::DataTimezone: Europe/Belgrade>

If you install tzinfo-data (or add it to your Gemfile), then you should get the correct result (which is actually Europe/Belgrade).

ZoneinfoDataSource doesn't attempt to understand symlinked zoneinfo files. This is because distributions that include symlinks don't tend to follow the Link definitions in the Time Zone Database (note that, in your example, Europe/Skopje and Europe/Podgorica should really both be linked to Europe/Belgrade). Following symlinks would therefore yield inconsistent and incorrect results.

@philr philr added the question label Jan 16, 2019

@philr philr closed this Jan 16, 2019

@jablan

This comment has been minimized.

Copy link
Author

jablan commented Jan 16, 2019

Thanks a lot Phil! I think it could be useful to mention this gotcha in the docs.

@philr

This comment has been minimized.

Copy link
Member

philr commented Jan 16, 2019

It is mentioned in the documentation for the canonical_zone method (see https://www.rubydoc.info/gems/tzinfo/2.0.0/TZInfo%2FTimezone:canonical_zone). I'll take a look and see if this can be made clearer.

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