rails/rails — pull request #17409 by philr (2014-10-27 22:47:42+00:00)
Title: Avoid TZInfo::AmbiguousTime exceptions on non-DST to non-DST transitions.

When the clock is set back in a time zone, there is a window of ambiguous local times that could either refer to the first or second occurrence of the time.

When the clock is set back due to a transition that ends DST, the `Time.zone.local` method handles this by interpreting the local time as DST.

However, if the clock is set back, but the time zone does not observe DST before or after the transition, then a `TZInfo::AmbiguousTime` exception is raised. This scenario occurred recently in Russia (Moscow, Magadan and other time zones):

At 02:00 local time in Moscow on 26 October 2014, the clocks where put back an hour. 01:00 local time therefore occurs twice. Moscow did not observe DST before or after the transition:

```
> Time.zone = 'Moscow'
> Time.zone.local(2014,10,26,1)
TZInfo::AmbiguousTime: 2014-10-26 01:00:00 UTC is an ambiguous local time.
from /home/psr/.rvm/gems/ruby-2.1.3/gems/tzinfo-1.2.2/lib/tzinfo/timezone.rb:415:in `period_for_local'
from /home/psr/rails/rails/activesupport/lib/active_support/values/time_zone.rb:413:in `period_for_local'
from /home/psr/rails/rails/activesupport/lib/active_support/time_with_zone.rb:386:in `get_period_and_ensure_valid_local_time'
from /home/psr/rails/rails/activesupport/lib/active_support/time_with_zone.rb:48:in `initialize'
from /home/psr/rails/rails/activesupport/lib/active_support/values/time_zone.rb:317:in `new'
from /home/psr/rails/rails/activesupport/lib/active_support/values/time_zone.rb:317:in `local'
```

This pull request makes a change such that non-DST to non-DST transitions that set the clock back are handled similarly to transitions that end DST:

```
> Time.zone = 'Moscow'
=> "Moscow"
> Time.zone.local(2014,10,26,1)
=> Sun, 26 Oct 2014 01:00:00 MSK +04:00
> Time.zone.local(2014,10,26,1).utc
=> 2014-10-25 21:00:00 UTC
```