diff options
author | Andrew White <andrew.white@unboxed.co> | 2017-11-11 15:19:29 +0000 |
---|---|---|
committer | Andrew White <andrew.white@unboxed.co> | 2017-11-15 09:48:50 +0000 |
commit | 2eea6458a14d99b19dffe8673015cde0800f128a (patch) | |
tree | 2dc03c75ff5b0cf9b151c6d55ab3ba86326f0a3c /activesupport/lib | |
parent | 23c41e4657a507c574e555339821f545c819e602 (diff) | |
download | rails-2eea6458a14d99b19dffe8673015cde0800f128a.tar.gz rails-2eea6458a14d99b19dffe8673015cde0800f128a.tar.bz2 rails-2eea6458a14d99b19dffe8673015cde0800f128a.zip |
Handle `TZInfo::AmbiguousTime` errors
Make `ActiveSupport::TimeWithZone` match Ruby's handling of ambiguous
times by choosing the later period, e.g.
Ruby:
```
ENV["TZ"] = "Europe/Moscow"
Time.local(2014, 10, 26, 1, 0, 0) # => 2014-10-26 01:00:00 +0300
```
Before:
```
>> "2014-10-26 01:00:00".in_time_zone("Moscow")
TZInfo::AmbiguousTime: 26/10/2014 01:00 is an ambiguous local time.
```
After:
```
>> "2014-10-26 01:00:00".in_time_zone("Moscow")
=> Sun, 26 Oct 2014 01:00:00 MSK +03:00
```
Fixes #17395.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 4d1fbd4453..639a066e28 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -506,7 +506,7 @@ module ActiveSupport # Available so that TimeZone instances respond like TZInfo::Timezone # instances. def period_for_local(time, dst = true) - tzinfo.period_for_local(time, dst) + tzinfo.period_for_local(time, dst) { |periods| periods.last } end def periods_for_local(time) #:nodoc: |