Is a given timezone in day light savings time?

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

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.

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

Colin Law 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

> Colin Law 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.

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

Fred

[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 (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

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