Fog Creek Software
Discussion Board




Daylight Saving Time

I am working on a project that requires converting UTC  time to various time zones. To my surprises, the Daylight Saving Time (DST) is being used in many countries, not only in US.

This site has much information:
http://webexhibits.org/daylightsaving/g.html

The rules seem complicated. It may take days to write a good accurate conversions. Can any one give me a suggestion/tip to reduce this pain?

It is nice to have an extra hour of daylight in summer evenings. But when it comes to coding, I wish all countries follow Japanese (they don't have DST).

Thank you.

Minh
Friday, July 23, 2004

Windows is able to make this conversion for various places: which it does using information in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation section of the registry.

Christopher Wells
Friday, July 23, 2004

There's gotta be existing OS calls or libraries that already do this sort of thing.  What language are you using?

it's been done
Friday, July 23, 2004

Have a look at Olsen data at ftp://elsie.nci.nih.gov/pub . I think there are many libraries especially on Unix which use this to make general timezone calculations based on daylight savings. 

BTW Japan is the only industralized country which does not have DST.

Code Monkey
Friday, July 23, 2004

I write for mobile devices, include CE and Symbian in C++. That was why I am trying to write some thing that not OS dependent.

Anyway is the Windows API for time zones realiable? I mean does it work with the date before and after EU DTS law changed?

Minh
Friday, July 23, 2004

dst is incrediablly dumb... but anyway, this looks like a good link:

http://www.twinsun.com/tz/tz-link.htm

the zoneinfo database goes back for a very long time. and thus is quite large.

is singapore an industrialized nation? do they have dst?

mb
Friday, July 23, 2004

oh, and phoenix and indianapolis.

mb
Friday, July 23, 2004

DST is not dumb in situations where your employer doesn't believe in Flex Time.

In occupations like that, it can be invaluable.

muppet
Friday, July 23, 2004

Singapore does not have DST but I do  not think it is classified as "Industralized" although it probably should be.

From what I know the list of "Industralized" nations is :

Denmark, Sweden, Norway, Netherlands, France, Luxembourg, Belgium, Finland, Canada, Germany, Switzerland, Australia, Ireland, United Kingdom, Austria, New Zealand, Portugal, Spain, Italy, Japan, and ofcourse the United States

Code Monkey
Friday, July 23, 2004

What a bizarre list. Singapore is certainly industrialized. They are not just outsourcing (I could see if you want to say that if they only do outsourced manufacturing they are not fully industrialized), but do a lot of their own design and development work as well.

Taiwan obviously belongs on the list too.

Probably a lot of countries. Mexico, Brazil, Chile. I guess since the revolution Argentina would not be on the list any more. How come some of teh euro states are listed more than once? If we do that, we should list California, Texas and Washington all as separate industrialized nations.

Dave Benson
Friday, July 23, 2004

Since Germany and Switzerland are no longer nations, the list should be tightened up to be: Europe, Canada, Australia, Japan and the US.

Dave Benson
Friday, July 23, 2004

Use OS functions...  I'm sure both Symbian and Windows CE have functions for handling time and date conversions.  If you want cross platform -- wrap these with own functions and use those.

Almost Anonymous
Friday, July 23, 2004

I wouldn't include New Zealand on the list. They have some factories but certainly fewer than Mexico, Swaziland or South Africa.

Dave Benson
Friday, July 23, 2004




Ha!  For all of our applications (which span multiple timezones, countires, *and* continents), we decided to punt local time and just use Zulu (Greenwich Mean Time) for everything.

Sure, it takes some getting used to, but for a bunch of math-strong people who know that they are at -5 and some other people are at +2, it's not too bad.

KC
Friday, July 23, 2004

" dst is incrediablly dumb... "

I used to think so too, until I read the rationale behind it.

In short: enables more outdoor activity during summertime evenings; saves energy (1-3.5%); reduces car crashes.

http://webexhibits.org/daylightsaving/c.html

- former car owner in Queens
Friday, July 23, 2004

I believe Raymond Chen talked about problems with converting UTC to local time.  There are many problems with historical conversion (some countries/areas didn't use DST during certain years (WWII), etc), but for current time it shouldn't be too much of a problem - there must be tested libraries for that.

Lou
Friday, July 23, 2004

Beware that your problem may not be solvable in an entirely algorithmic fashion.

At least one country (Israel) converts to daylight saving time depending on the ruling of a local board of religious experts. As I understand it, the date is not reliably predictable in advance.

Other countries have tweaked daylight saving time in an ad-hoc fashion in the past as a result of special situations -- including, IIRC, the presence of the Olympic Games and in wartime.

John C.
Friday, July 23, 2004

Theres also Indiana (US), which most of the state observes DST but parts don't.

Yo
Friday, July 23, 2004

Jordan uses DST all year.

Oren Miller
Friday, July 23, 2004

Actually, in Indiana, most of the does *not* observer DST, while parts do.

http://www.timetemperature.com/tzus/indiana_time_zone.shtml

Oren Miller
Friday, July 23, 2004

I don't know how much this is going to help, but you need to be aware that John C. is correct, and the problem is worse than you think.

There is _no_ canonical source for determining worldwide observance of DST. Period.

I work with airlines, and we we can at least cheat; there _is_ a canonical source for DST at all airports. If it's practical to correlate to the nearest airport, you can use GMT and apply the airport offset c/w DST offset.

You can download the raw data from the Digital Aeronautical Flight Information Files (DAFIF) for free, but working with it is no fun.  I don't have the url for the DAFIF files immediately in front of me, but you should be able to Google for  them.

Good luck, you'lll need it.

Mongo
Friday, July 23, 2004

A few observations:

(1) Daylight saving time (DST) does not magically give you any more daylight. There would be exactly as much daylight no matter what you set your watch to. At best, DST gives you a tradeoff between daylight in the morning and in the evening. If your employer simply said "tomorrow you can come from 9 o'clock instead of 8 o'clock", you wouldn't have to run around and change the time on all your VCRs.

(2) There is no mapping between a geographical longitude to a timezone or to a DST scheme. You have bizarre situations like the Arizona being in the Mountain time zone but, unlike Utah, not observing DST, except for the Navaho nation, which does.

(3) There is no one-to-one mapping from a local time (observing DST) to UTC (although there is the other way around). This stems from the fact that there is an hour in local time that comes twice in the shift after the autumnal equinox and you don't know in which of these you are without extra information.

http://www.standardtime.com/

'Nuff said.

Roland Kaufmann
Friday, July 23, 2004

>What a bizarre list

Well if it is good enough for UNICEF I guess it is good enough for me.

http://www.unicef.org/pon98/indust7.htm

But your point about why Taiwan and Singapore is not on the list is a valid one and the reason I guess is that Taiwan is technically not a country and Singapore probably does not have the GDP but then how Luxembourg got on the list is a mystery!

Code Monkey
Friday, July 23, 2004

Dave: What Euro states are listed more than once? I don't see any duplication in Code Monkey's list.

Ian
Friday, July 23, 2004

>Since Germany and Switzerland are no longer nations,

Huh? That is news to me.  Ofcourse they are nations...if they have a domain they are a nation :-)

>the list should be tightened up to be: Europe, Canada, Australia, Japan and the US.

I do not think that nations like Serbia, Croatia, Albania etc can be classified as Industralized inspite of being in Europe.  Also if you include Taiwan you have to include South Korea too!

Code Monkey
Friday, July 23, 2004

There are also a handful of time zones that are 30 minute offset instead of an hour.

I agree with the earlier comment -- convert everything to GMT on input, and convert back to local time on display, using locale info on the local machine.  Do all behind-the-scenes computation using the GMT values.

AMS
Friday, July 23, 2004

Thank you all for your input.

This is what I'm going to do:

1. Export HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones in my XP box to an array of TIME_ZONE_INFORMATION then embed this in my code.

2. Write my own logic to do the conversion using the time zone data.

This approach may not cover all past time span, but will work for current time as good as Windows ;-). And it is platform independent.

The database from http://www.twinsun.com/tz/tz-link.htm
is comprehensive but too overkilled for my scope.

Minh
Friday, July 23, 2004

I like Daylight Saving Time.  What I hate is going _off_ Daylight Saving Time.  I'd rather have it be dark when I go to work and light when I go home.  Actually, they did that one year; does anybody remember?  I think it was when I was in junior high, about '88 or '89...

Kyralessa
Friday, July 23, 2004

why not just convert on the local machine? of course you're assuming the time/timezone is set right, but is that an issue?

basically, always send either GMT, or local time + local offset, to the server, and always send GMT to the client, which can then convert before display.

mb
Friday, July 23, 2004

"To my surprises, the Daylight Saving Time (DST) is being used in many countries, not only in US."

Brace yourself; English is spoken outside of America too.

always amazed by pure ignorance
Friday, July 23, 2004

When I was working in Mexico, the company I was at didn't honor the local DST rules for their servers because the dates that DST changed over was different for Mexico than for the U.S. It hindered their ability to work with the U.S.

It was a pain in the buttocks for me because I would authenticate on their servers and my clock would change by an hour because my computer was set to have DST when theirs did not, and then I couldn't log on remotely to my home server in the U.S. because my clock was off by an hour and the server didn't like that.

Ankur
Friday, July 23, 2004

Server clocks should always be synched to GMT.  Set the locale so that it shows local time properly, but the clock should be GMT.

AMS
Friday, July 23, 2004

"Brace yourself; English is spoken outside of America too. "

Pls excuse my ignorance. I am from a culture that never has DST.

"why not just convert on the local machine? of course you're assuming the time/timezone is set right, but is that an issue?"

The module is to convert the GMT time to multiple international time zones not set in the system level. So the machine's local time zone has no use here.

Minh
Saturday, July 24, 2004

Just to let people know.  Not all of Australia has DST.  Here is Western Australia we don't have it, but most of Australia does.

Michael Aldred
Saturday, July 24, 2004

If you just want current offsets, not history, I believe Windows has this all built in, no need to export from your 'clients'. I dug up someone's .NET class to do this a month or two ago for someone who needed it, look on the gotdotnet messageboard (I think) for a discussion with multiple solutions, one of which is the one you want. It's just a short wrapper for Win32 calls, so even if you're not using .NET it's a useful hint on where to dig in the docs.

mb
Saturday, July 24, 2004

ah, a quick search for 'timezone gotdotnet' turned this up. Wonder if adding 'gotdotnet' is always a good idea?

http://forums.asp.net/Forums/PrintPost.aspx?PostID=453373

mb
Saturday, July 24, 2004

Often the list of "industrialized countries" is equated to the members of the OECD (Organisation for Economic Co-operation and Development). OECD now has 30 members. It includes all of the counties in "code monkey's list, plus a few more: Turkey (in OECD from its start in 1961) and eastern European countries joining in the 1990s. Singapore is not a member.

Not being in the OECD does not mean that a country is not industrialized, but it does mean that it will often be omitted from the list.

List of OECD members: http://www.oecd.org/document/58/0,2340,en_2649_201185_1889402_1_1_1_1,00.html

John
Saturday, July 24, 2004

Singapore doesn't have DST because it's a tropical country and there is almost no difference between "summer" and "winter" (also applies to temperature - this month in Sri Lanka has been incredibly cool and I 've often not even bothered to turn the fan on).

---"There are also a handful of time zones that are 30 minute offset instead of an hour."----

Sri Lanka used to be one of them until a few years back. Arthur C. Clarke spent thirty years complaining.

Stephen Jones
Sunday, July 25, 2004

Israel's DST time is a political decision, often influenced by religious parties; Now that the ultra-religious are not part of the government, it seems like we'll have indefinite DST in Israel.

Indefinite until they do enter the government once more .....

Ori Berger
Sunday, July 25, 2004

"but then how Luxembourg got on the list is a mystery!"

That depends on what the author(s) of the list mean by "industrialized". I remember in the early 80s it was used to put apart the "developed nations" from the "3rd world nations".

In that sense, Luxembourg definitely belongs in that list, as it's famed for having one of the highest standards of living in the EU.

Paulo Caetano
Monday, July 26, 2004

DST and Singapore.

Singapore is almost exactly on the Equator. Because of that there is no significant variation in the length of daylight vs. night at different parts of the year. So why go to DST when you're not saving.

Arizona and Hawaii (in the United States), don't go on DST. Indiana doesn't except for a few locations near big cities in other states.

Indiana is also in two different time zones. Great fun, I'm sure.

dot
Monday, July 26, 2004

*  Recent Topics

*  Fog Creek Home