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
TZInfo with ActiveSupport - Samoa Timezone error #66
Comments
It looks like there is a bug with the TZInfo zoneinfo data source that is causing the Pacific/Apia time zone (that Active Support calls Samoa) to be represented with a base offset of -11 hours and a daylight savings offset of either +24 or +25 hours (instead of a base offset of +13 hours and a daylight savings offset of either 0 or +1 hour): require 'tzinfo'
TZInfo::DataSource.set(:zoneinfo)
period = TZInfo::Timezone.get('Pacific/Apia').period_for_utc(Time.utc(2017, 3, 6))
period.utc_offset / 3600 # => -11
period.std_offset / 3600 # => 25
period.utc_total_offset / 3600 # => 14 The reason for the difference between The expected behaviour is that Pacific/Apia switched from one side of the International Date Line to the other in December 2011. I suspect that the code that attempts to derive the daylight savings offset from zoneinfo files is not handling this change correctly. I'll look into fixing the bug. In the mean time, you can work around the problem by using the require 'tzinfo'
TZInfo::DataSource.set(:ruby)
period = TZInfo::Timezone.get('Pacific/Apia').period_for_utc(Time.utc(2017, 3, 6))
period.utc_offset / 3600 # => 13
period.std_offset / 3600 # => 1
period.utc_total_offset / 3600 # => 14 To change the data source, you'll need to add a dependency on |
Thanks @philr ! |
Resolves #66, correctly handling Pacific/Apia switching from one side of the International Date Line to the other whilst observing daylight savings time. The previous algorithm only looked one transition forward and back and always preferred the prior period to define the utc_offset of a DST period. The new algorithm considers all transitions forward and back until a non-DST period is found and defines utc_offset of a DST period based on the smallest difference. (cherry picked from commit 45dcc3d)
The fix for this issue has now been released in version 1.2.3. |
I am having the same issue as this user, that created this issue in repository of Rails: (rails/rails#27419)
Steps to reproduce
In rails console.
DateTime.now.in_time_zone("Samoa")
Returns a date with a UTC offset of + 14:00ActiveSupport::TimeZone.new('Samoa').utc_offset/60/60
Returns -11Expected behavior
ActiveSupport::TimeZone.new('Samoa').utc_offset/60/60
Should return 14 or 13 based on daylight savings timeActual behavior
ActiveSupport::TimeZone.new('Samoa').utc_offset/60/60
Returns -11System configuration
Rails version: 5.0.2
Ruby version: 2.3.3
The text was updated successfully, but these errors were encountered: