[TZInfo-users] Resolving local_to_utc ambiguities

Philip Ross phil.ross at gmail.com
Sat Nov 14 10:30:55 EST 2009

Hi Stephan,

2009/11/13 Stephan Wehner <stephanwehner at gmail.com>:
> (The ambiguity being that some local times may correspond to several
> UTC times, for example, when switching to daylight savings time, when
> there are "two 2 AMs".)
> In what circumstances would it happen that dst=true or false is not
> enough to "resolve the ambiguity"?

This will happen when the base UTC offset of a timezone is decreased
(i.e. the local clocks are put back), but the timezone does not change
between standard and daylight savings time at the point of change.

There are many instances where this condition happens in the timezone
data. The attached script will print all of these instances. One of
the more recent occurrences is the America/Argentina/San_Luis zone,
where at midnight on 2008-01-21, the clock is put back to 23:00:00 on
2008-01-20, but daylight savings time is still observed:

America/Argentina/San_Luis  Mon Jan 21 01:59:59 2008 UTC = Sun Jan 20
23:59:59 2008 ARST isdst=1
America/Argentina/San_Luis  Mon Jan 21 02:00:00 2008 UTC = Sun Jan 20
23:00:00 2008 WARST isdst=1

If you try to convert 23:30:00 from local time to UTC, then you will
need to use the block to resolve the ambiguity.

> Are there ever more than two elements in the "periods" array that is
> passed to the block to pick from?

This could happen if the base UTC offset of a timezone was decreased
twice in succession. For example, consider a timezone was initially at
UTC+3, but then put its clocks back to UTC+2 and then an hour later
put its clocks back to UTC+1:

03:00 UTC+3 = 00:00 UTC
03:59 UTC+3 = 00:59 UTC
03:00 UTC+2 = 01:00 UTC
03:59 UTC+2 = 01:59 UTC
03:00 UTC+1 = 02:00 UTC

In this example, attempting to convert 03:30 from local time to UTC
would result in three possible periods passed to the block.

I am not however, aware of any such examples in the timezone database,
so the maxinum number of elements you'll see in the periods array is



Phil Ross
http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
-------------- next part --------------
A non-text attachment was scrubbed...
Name: findambigioustz.rb
Type: application/octet-stream
Size: 662 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/tzinfo-users/attachments/20091114/e02c726f/attachment.obj>

More information about the TZInfo-users mailing list