[TZInfo-users] Bug with UTC and system time

Philip Ross phil.ross at gmail.com
Sat Jan 11 19:29:44 UTC 2014

On 10 January 2014 19:47, Peter Hamilton <peterghamilton at gmail.com> wrote:
> I opened a ticket at https://github.com/tzinfo/tzinfo/issues/13

Thank you for the report.

> The fix is easy, but I'm having a hard time writing a test for it.
> So far, other than the system being set to UTC, I can't seem to produce a
> time object like the one I show in the ticket.
> Is there any way to create a Time object with an arbitrary time zone? It is
> my understanding that the time is either local or UTC, so the answer to my
> question is no (which is why tzinfo exists right?).

It isn't possible to create a Time object with an arbitrary time zone.
Time instances can either use the system (local) time zone or UTC.
However, on most platforms (Windows is the notable exception) it is
possible to change the local time zone of the current process by
setting the TZ environment variable. For example:

2.1.0p0 :001 > ENV['TZ'] = 'America/Los_Angeles'
 => "America/Los_Angeles"
2.1.0p0 :002 > Time.now.zone
 => "PST"
2.1.0p0 :003 > ENV['TZ'] = 'UTC'
 => "UTC"
2.1.0p0 :004 > Time.now.zone
 => "UTC"

> If we can only create local or UTC objects, is there a way to ensure the
> local object thinks the time zone is UTC?
> Any other ideas for testing this?

I have committed a fix
with tests that temporarily adjust the TZ environment variable. On
Windows and other platforms where setting TZ doesn't change the time
zone, the tests will pass, but won't actually test for this issue.

Kind regards,


More information about the TZInfo-users mailing list