# Is a given timezone in day light savings time?

**URL:** <https://www.ruby-forum.com/t/is-a-given-timezone-in-day-light-savings-time/176548>\
**Category:** Rails\
**Created:** [October 1, 2009, 11:05pm UTC](https://www.ruby-forum.com/t/is-a-given-timezone-in-day-light-savings-time/176548 "2009-10-01T23:05:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [October 1, 2009, 11:05pm UTC](https://www.ruby-forum.com/t/is-a-given-timezone-in-day-light-savings-time/176548/1 "2009-10-01T23:05:45Z")

</div>

Is there a way to figure out if a given timezone is in daylight  
savings?

I have a reminder system setup that allows users to setup reminders  
(daily, weekly, monthly, or yearly) however it does not currently  
account for daylight savings. I am not exactly sure how to do this but  
here is what I was thinking. I stored the time they want to get the  
reminder as a datetime but only pay attention to the portions that i  
need to. For example, on the daily reminders i dont pay attention to  
the date, month, and year. I also store each users timezone. I have a  
cron job that runs through all of the reminders setup and if the time  
has come across then it sends off a reminder. This all works except i  
dont account for daylight savings. I did not even have to worry about  
timezones except on the UI end as everythign is stored in UTC and i do  
my comparisons in UTC. However, it seems like I will need to look at  
if a given user resides in a timezone that is in daylight savings and  
adjust the time if necessary. Does that sound right? Is there a way to  
see if a given timezone is currently in day light saving?

thanks

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [October 1, 2009, 11:17pm UTC](https://www.ruby-forum.com/t/is-a-given-timezone-in-day-light-savings-time/176548/2 "2009-10-01T23:17:51Z")

</div>

tashfeen.ekram wrote:

> Is there a way to figure out if a given timezone is in daylight  
> savings?

You would have to look in a Geopolitical timezone database. Operating  
systems have them or they are built into a VM if necessary (I know there  
is one for the Java VM for example).

There is no one-to-one correspondence between timezones and daylight  
savings, so the values have to be looked up. You would have to know when  
DST starts and ends per zone, per political boundary, per year, etc. And  
also the value of the change. Some areas only change by 30 mins instead  
of an hour for example.

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [October 1, 2009, 11:30pm UTC](https://www.ruby-forum.com/t/is-a-given-timezone-in-day-light-savings-time/176548/3 "2009-10-01T23:30:56Z")

</div>

2009/10/1 tashfeen.ekram [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> the date, month, and year. I also store each users timezone. I have a  
> cron job that runs through all of the reminders setup and if the time  
> has come across then it sends off a reminder. This all works except i  
> dont account for daylight savings. I did not even have to worry about  
> timezones except on the UI end as everythign is stored in UTC and i do  
> my comparisons in UTC. However, it seems like I will need to look at  
> if a given user resides in a timezone that is in daylight savings and  
> adjust the time if necessary. Does that sound right? Is there a way to  
> see if a given timezone is currently in day light saving?

If you have the local time in a known time zone put it into a ruby  
Time object (which, confusingly, includes a date) then you can use  
dst? to determine whether it is in dst or not.

Colin

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [October 2, 2009, 1:25am UTC](https://www.ruby-forum.com/t/is-a-given-timezone-in-day-light-savings-time/176548/4 "2009-10-02T01:25:47Z")

</div>

Colin L. wrote:

> If you have the local time in a known time zone put it into a ruby  
> Time object (which, confusingly, includes a date) then you can use  
> dst? to determine whether it is in dst or not.

Cool. I hadn’t had a chance to go looking for a method in Ruby to  
determine dst. I knew one exited in Java. It’s good to know that .dst?  
is the ticket. Do you know whether Ruby maintains it’s own timezones  
database or asks the host OS to look it up from the system’s database?

> Time object (which, confusingly, includes a date)  
> Confusing to some maybe, but anyone who has ever done any serious date  
> math knows that time is meaningless apart from date.

After years in existence the Java folks still aren’t completely happy  
with the standard Date and Time objects. In fact it’s been redone  
several times, and still people often dump the standard classes in favor  
of Joda time. It might sound simple, but in reality it’s far from it.

[http://joda-time.sourceforge.net/](http://joda-time.sourceforge.net/)

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [October 2, 2009, 11:02am UTC](https://www.ruby-forum.com/t/is-a-given-timezone-in-day-light-savings-time/176548/5 "2009-10-02T11:02:17Z")

</div>

On Oct 2, 9:06 am, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > determine dst. I knew one exited in Java. It’s good to know that .dst?  
> > is the ticket. Do you know whether Ruby maintains it’s own timezones  
> > database or asks the host OS to look it up from the system’s database?
> 
> Don’t know. I guess the system or Ruby would have to be updated  
> regularly to keep it up to date, DST dates keep changing.

The tzinfo gem is regularly updated based on a public domain database  
of dst rules etc ([matsuo family](http://www.twinsun.com/tz/tz-link.htm))

Fred

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [October 2, 2009, 11:08am UTC](https://www.ruby-forum.com/t/is-a-given-timezone-in-day-light-savings-time/176548/6 "2009-10-02T11:08:43Z")

</div>

2009/10/2 Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> On Oct 2, 9:06Â am, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> [snip]
> 
> > Don’t know. I guess the system or Ruby would have to be updated  
> > regularly to keep it up to date, DST dates keep changing.
> 
> The tzinfo gem is regularly updated based on a public domain database  
> of dst rules etc ([matsuo family](http://www.twinsun.com/tz/tz-link.htm))

gem list does not show that I have the tzinfo gem installed, yet  
Time.dst? works for me, at least in my timezone.

Colin

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [October 2, 2009, 11:12am UTC](https://www.ruby-forum.com/t/is-a-given-timezone-in-day-light-savings-time/176548/7 "2009-10-02T11:12:49Z")

</div>

On 2 Oct 2009, at 10:06, Colin L. wrote:

> > > 
> > 
> > The tzinfo gem is regularly updated based on a public domain database  
> > of dst rules etc ([matsuo family](http://www.twinsun.com/tz/tz-link.htm))
> 
> gem list does not show that I have the tzinfo gem installed, yet  
> Time.dst? works for me, at least in my timezone.

I believe that just uses whatever knowledge the system has of  
timezones, whereas tzinfo does not rely on that (and of course easier  
to update if needed). Also has various utilities related to  
manipulating timezones etc.

Rails bundles in a version of tzinfo.

Fred

---

<div class="post-metadata">

**Author:** ![tashfeen.ekram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tashfeen.ekram](https://www.ruby-forum.com/u/tashfeen.ekram)\
**Post date:** [October 2, 2009, 10:08am UTC](https://www.ruby-forum.com/t/is-a-given-timezone-in-day-light-savings-time/176548/8 "2009-10-02T10:08:25Z")

</div>

2009/10/2 Robert W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Colin L. wrote:
> 
> > If you have the local time in a known time zone put it into a ruby  
> > Time object (which, confusingly, includes a date) then you can use  
> > dst? to determine whether it is in dst or not.
> 
> Cool. I hadn’t had a chance to go looking for a method in Ruby to  
> determine dst. I knew one exited in Java. It’s good to know that .dst?  
> is the ticket. Do you know whether Ruby maintains it’s own timezones  
> database or asks the host OS to look it up from the system’s database?

Don’t know. I guess the system or Ruby would have to be updated  
regularly to keep it up to date, DST dates keep changing.

> > Time object (which, confusingly, includes a date)  
> > Confusing to some maybe, but anyone who has ever done any serious date  
> > math knows that time is meaningless apart from date.

When there is also a DateTime class it is confusing.

The discussion has been had many times before, but there are times  
when a TimeOfDay class would be useful without a date. For an alarm  
that goes off at the same time every day for example.

> After years in existence the Java folks still aren’t completely happy  
> with the standard Date and Time objects. In fact it’s been redone  
> several times, and still people often dump the standard classes in favor  
> of Joda time. It might sound simple, but in reality it’s far from it.

Definitely

Colin
