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

Incorrect offsets for dates beyond 2037. #70

Closed
Mihail-K opened this Issue Aug 31, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@Mihail-K

Mihail-K commented Aug 31, 2017

Referencing back to the issue in Rails, rails/rails#30408

Specifically, EDT is not included in list of time periods beyond November 2nd, 2037.

time_zone = TZInfo::Timezone.get('America/Toronto')
irb(main):005:0> time_zone.periods_for_local(Time.new(2017, 8, 27, 10, 0, 0))
=> [#<TZInfo::TimezonePeriod: #<TZInfo::TimezoneTransitionDefinition: #<TZInfo::TimeOrDateTime: 1489302000>,#<TZInfo::TimezoneOffset: -18000,3600,EDT>>,#<TZInfo::TimezoneTransitionDefinition: #<TZInfo::TimeOrDateTime: 1509861600>,#<TZInfo::TimezoneOffset: -18000,0,EST>>>]
irb(main):006:0> time_zone.periods_for_local(Time.new(2047, 8, 27, 10, 0, 0))
=> [#<TZInfo::TimezonePeriod: #<TZInfo::TimezoneTransitionDefinition: #<TZInfo::TimeOrDateTime: 2140668000>,#<TZInfo::TimezoneOffset: -18000,0,EST>>,nil>

This is problematic because it causes a discrepancy in behaviour between Postgres and our Rails application, where two different dates would be produced by applying time zone offsets.

@philr

This comment has been minimized.

Show comment
Hide comment
@philr

philr Aug 31, 2017

Member

I assume that you are using TZInfo with the zoneinfo datasource (reading system zoneinfo files rather than using the tzinfo-data gem). You can the datasource being used with TZInfo::DataSource.get.

Each zoneinfo file includes a list of the transitions that occur in a time zone. This list obviously cannot extend infinitely far into the future, so there is a cut-off where the transitions end. A "POSIX-TZ-environment-variable-style string" is also included in the file. This can be used to calculate the times of subsequent transitions. The zic command that generates zoneinfo files currently includes transitions up to around the year 2037.

TZInfo is only able to read the list of transitions from zoneinfo files. It does not evaluate the POSIX-TZ string. When used with the zoneinfo data source, TZInfo will therefore not return any transitions beyond about 2037 (and local times beyond this point will remain at the same offset).

I intend to look at supporting the POSIX-TZ string in a future version of TZInfo.

For the time being though, you might like to consider installing the tzinfo-data gem as a datasource. tzinfo-data is based on the same IANA Time Zone database as the zoneinfo files and includes 50 years of future transitions.

To use tzinfo-data as a datasource, just add gem 'tzinfo-data' to your Gemfile. TZInfo will detect and use it in preference to the zoneinfo files. Since your Rails issue concerned compatibility with Postgres, you should probably select a version of tzinfo-data that matches the version of the Time Zone Database being used by Postgres (e.g. v1.2016.10 of tzinfo-data for tzdata2016j, v1.2017.2 for tzdata2017b, etc).

It is also worth noting that making assumptions about local times far in the future can be dangerous. The rules concerning time zone offsets and daylight savings time can and do change.

Member

philr commented Aug 31, 2017

I assume that you are using TZInfo with the zoneinfo datasource (reading system zoneinfo files rather than using the tzinfo-data gem). You can the datasource being used with TZInfo::DataSource.get.

Each zoneinfo file includes a list of the transitions that occur in a time zone. This list obviously cannot extend infinitely far into the future, so there is a cut-off where the transitions end. A "POSIX-TZ-environment-variable-style string" is also included in the file. This can be used to calculate the times of subsequent transitions. The zic command that generates zoneinfo files currently includes transitions up to around the year 2037.

TZInfo is only able to read the list of transitions from zoneinfo files. It does not evaluate the POSIX-TZ string. When used with the zoneinfo data source, TZInfo will therefore not return any transitions beyond about 2037 (and local times beyond this point will remain at the same offset).

I intend to look at supporting the POSIX-TZ string in a future version of TZInfo.

For the time being though, you might like to consider installing the tzinfo-data gem as a datasource. tzinfo-data is based on the same IANA Time Zone database as the zoneinfo files and includes 50 years of future transitions.

To use tzinfo-data as a datasource, just add gem 'tzinfo-data' to your Gemfile. TZInfo will detect and use it in preference to the zoneinfo files. Since your Rails issue concerned compatibility with Postgres, you should probably select a version of tzinfo-data that matches the version of the Time Zone Database being used by Postgres (e.g. v1.2016.10 of tzinfo-data for tzdata2016j, v1.2017.2 for tzdata2017b, etc).

It is also worth noting that making assumptions about local times far in the future can be dangerous. The rules concerning time zone offsets and daylight savings time can and do change.

@philr philr closed this Sep 8, 2017

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