views:

140

answers:

2

Okay this may be a simple question but I have yet to come with a working solution, so to anyone who can help thanks in advance.

Consider the following scenario: We have a web-application running on MySQL (if you need to know) that is time dependent say an application that sends an email at the user specified time. Now every user has set his proper timezone/city and the servers are running on UTC for simplicity. The accurate time would be server time + timezone + daylight saving. The user wants the email to reach him on Jan 4 2010 5:00 pm his time. My question would be how to get the correct daylight saving? Meaning is this user in a region that observes DST if so did he/she observe it or not yet?

My first impulse would be to find a web-service that given the current timezone/city would give you the proper daylight saving. So far i have not found one. I am discouraged by the second idea, that I have to set rules for DST since these change from year to year and in some countries by more than a day or two.

Any help greatly appreciated.

A: 

Store your dates as seconds since Jan 1, 1970 GMT in your database and you'll always have the time dealt with. When the user enters in his time, convert it as appropriately using the correct timezone settings and you're done.

Your servers are already running without timezones so when the time comes it's an easy select.

Here's some code to do timezone conversion in LISP:

Epsilon Prime
Except he is asking how to get the correct timezone settings...
Jason Berkan
Yeah, the mysql bit threw me off -- a lot of people tend to put their dates in as DateTime instead of int(11) and that tends to give them tons of DST problems.
Epsilon Prime
I understand your suggestion but as Jason pointed, for me to move to GMT timing i would need to know if the user's time in the future will be subject to daylight saving or not which is basically the original question but asked differently. Also on side note the decode-universal-time function depends on your server's clock and DST setting which would for our question purpose be not the same as the user's
Mackram
+1  A: 

If your programming language doesn't have support for fancy time zone logic, you don't have to program the rules by yourself. You just need to program support for the zoneinfo database.

Jason Berkan
Thanks Jason for the help in pointing the zone info database. I had hoped for since I wanted to be able to query some server but the solution is good enough given that I could not find the first one.
Mackram
For those of you interested in Common Lisp like myself I just want to point out that i learned about local-time library (currently tested on SBCL) that offers the support for zoneinfo.
Mackram