# Time zone offset and daylight saving

**URL:** <https://rubytalk.org/t/time-zone-offset-and-daylight-saving/24509>\
**Category:** ruby-talk\
**Created:** [1 February 2006 21:38 UTC](https://rubytalk.org/t/time-zone-offset-and-daylight-saving/24509 "2006-02-01T21:38:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JM1](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@JM1](https://rubytalk.org/u/JM1)\
**Post date:** [1 February 2006 21:38 UTC](https://rubytalk.org/t/time-zone-offset-and-daylight-saving/24509/1 "2006-02-01T21:38:55Z")

</div>

My understanding is that a time change is implemented by switching time  
zones; you change from Pacific Standard Time to Pacific Daylight Time.  
Pacific Standard Time would continue to have the same offset in July as it  
would in January; it's just that in July no clocks are set to Pacific  
Standard. (Except the clock on my kitchen scale, of course...)

And good luck figuring out when you're supposed to switch; it's arbitary,  
set by legislation, not by something you can figure out. And the US at  
least will be changing in the near future. And there are places that never  
make the switch, too. Google for things like 'daylight savings time zone'  
and you'll get an idea of the pain involved.

- James

\<easleydp@gmail.com\> wrote in message  
news:1138565845.900427.111410@g14g2000cwa.googlegroups.com...

> **···**
>
> > I don't seem to be able to correctly calculate the time offset between  
> > two time zones when daylight saving is in effect. The code below  
> > demonstrates that Ruby knows about daylight saving, but I get the wrong  
> > answer when I calculate the offset.
> > 
> > BTW, yes, I know I can use Time#utc\_offset, but I believe that depends  
> > on me actually being in that timezone. I'm looking for a way to  
> > calculate the offset between two arbitrary timezones, neither of which  
> > is my local timezone.
> > 
> > Thanks for any help.
> > 
> > David

---

<div class="post-metadata">

**Author:** ![Easleydp](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@Easleydp](https://rubytalk.org/u/Easleydp)\
**Post date:** [1 February 2006 21:43 UTC](https://rubytalk.org/t/time-zone-offset-and-daylight-saving/24509/2 "2006-02-01T21:43:02Z")

</div>

Thanks for the help, guys.

Took a look at the Python port of the tz database, then discovered  
there's a Ruby version! Check out these links:

Rubyforge: [http://tzinfo.rubyforge.org/](http://tzinfo.rubyforge.org/)  
How to use with Rails:  
[http://lunchroom.lunchboxsoftware.com/pages/tzinfo\_rails](http://lunchroom.lunchboxsoftware.com/pages/tzinfo_rails)

---

<div class="post-metadata">

**Author:** ![Jamis\_Buck2](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@Jamis\_Buck2](https://rubytalk.org/u/Jamis_Buck2)\
**Post date:** [1 February 2006 22:22 UTC](https://rubytalk.org/t/time-zone-offset-and-daylight-saving/24509/3 "2006-02-01T22:22:40Z")

</div>

The TZInfo lib for Ruby does a pretty good job of encapsulating all those rules:

&nbsp;&nbsp;&nbsp;[http://tzinfo.rubyforge.org/](http://tzinfo.rubyforge.org/)

- Jamis

> **···**
>
> On Feb 1, 2006, at 2:38 PM, JM wrote:
> 
> > My understanding is that a time change is implemented by switching time  
> > zones; you change from Pacific Standard Time to Pacific Daylight Time.  
> > Pacific Standard Time would continue to have the same offset in July as it  
> > would in January; it's just that in July no clocks are set to Pacific  
> > Standard. (Except the clock on my kitchen scale, of course...)
> > 
> > And good luck figuring out when you're supposed to switch; it's arbitary,  
> > set by legislation, not by something you can figure out. And the US at  
> > least will be changing in the near future. And there are places that never  
> > make the switch, too. Google for things like 'daylight savings time zone'  
> > and you'll get an idea of the pain involved.
> > 
> > - James
> > 
> > \<easleydp@gmail.com\> wrote in message  
> > news:1138565845.900427.111410@g14g2000cwa.googlegroups.com...
> > 
> > > I don't seem to be able to correctly calculate the time offset between  
> > > two time zones when daylight saving is in effect. The code below  
> > > demonstrates that Ruby knows about daylight saving, but I get the wrong  
> > > answer when I calculate the offset.
> > > 
> > > BTW, yes, I know I can use Time#utc\_offset, but I believe that depends  
> > > on me actually being in that timezone. I'm looking for a way to  
> > > calculate the offset between two arbitrary timezones, neither of which  
> > > is my local timezone.
> > > 
> > > Thanks for any help.
> > > 
> > > David

---

<div class="post-metadata">

**Author:** ![Trevor\_Squires](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Trevor\_Squires](https://rubytalk.org/u/Trevor_Squires)\
**Post date:** [1 February 2006 22:36 UTC](https://rubytalk.org/t/time-zone-offset-and-daylight-saving/24509/4 "2006-02-01T22:36:18Z")

</div>

Hi,

Regarding "good luck figuring out when you're supposed to switch" - Phil Ross has released a ruby library that uses the Olson Timezone database (considered the definitive source for world timezones).

You're right that it's a pain (it's a political issue after all) but it's not insurmountable if you use the Olson data.

Phil's library is available at:

[http://tzinfo.rubyforge.org/](http://tzinfo.rubyforge.org/)

HTH,  
Trevor

> **···**
>
> On 1-Feb-06, at 1:38 PM, JM wrote:
> 
> > My understanding is that a time change is implemented by switching time  
> > zones; you change from Pacific Standard Time to Pacific Daylight Time.  
> > Pacific Standard Time would continue to have the same offset in July as it  
> > would in January; it's just that in July no clocks are set to Pacific  
> > Standard. (Except the clock on my kitchen scale, of course...)
> > 
> > And good luck figuring out when you're supposed to switch; it's arbitary,  
> > set by legislation, not by something you can figure out. And the US at  
> > least will be changing in the near future. And there are places that never  
> > make the switch, too. Google for things like 'daylight savings time zone'  
> > and you'll get an idea of the pain involved.
> > 
> > - James
> > 
> > \<easleydp@gmail.com\> wrote in message  
> > news:1138565845.900427.111410@g14g2000cwa.googlegroups.com...
> > 
> > > I don't seem to be able to correctly calculate the time offset between  
> > > two time zones when daylight saving is in effect. The code below  
> > > demonstrates that Ruby knows about daylight saving, but I get the wrong  
> > > answer when I calculate the offset.
> > > 
> > > BTW, yes, I know I can use Time#utc\_offset, but I believe that depends  
> > > on me actually being in that timezone. I'm looking for a way to  
> > > calculate the offset between two arbitrary timezones, neither of which  
> > > is my local timezone.
> > > 
> > > Thanks for any help.
> > > 
> > > David
> 
> --  
> Trevor Squires  
> [http://somethinglearned.com](http://somethinglearned.com)
