- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The frist WTF is of course being a nephew.
Admin
The second letting the CTO hire his own nephew
Admin
And of course daylight savings times do not change at midnight (at least in the UK they change at 2am, Winter & 1am, Summer)
if you MUST re-invent the wheel instead of using existing tools then it is vital to know how they roll.
Admin
Was the nephew planning to edit this code every year, as part of some sort of job security scheme?
Admin
Dates and Times are so full of gotchas that your home brewed system is NEVER going to be close to bug-free. Use the libraries.
Admin
This is one topic that is full of subtle bugs that make you itch. A small sample of C# Daylight Savings Time queries from SO show that even the API's are buggy:
http://stackoverflow.com/questions/6214633/c-sharp-daylight-savings-duplicate-hour-convert-to-utc http://stackoverflow.com/questions/16826234/how-to-determine-if-specific-date-is-daylight-savings-time-or-no http://stackoverflow.com/questions/10884618/asp-net-time-conversion-on-server-daylight-savings
Admin
Even the libraries are full of features. Time Zones, DST and history records are amazingly hard to get correct using any library from any system/language
Admin
Admin
There you go. The real WTF fixed.
Admin
Fortunately I have no nephews, only nieces. One of them is the wife of a policeman and is in a position of administration in her local church, while the other runs a workshop that manufactures special effects for movies (last major contract was the last Hellraiser movie). So it's unlikely that I will be tempted to get said non-existent nephew into a position of designing a new software project for the company I work for.
Oh hang on, tell a lie, I just remembered I do have a nephew. His specialties include skateboarding, posting up vids of himself playing guitar on youTube and failing to turn up on time (or even at all, some days) to his job behind the counter of an outlet of a famous national chain of bakery shops. I sincerely hope I'm not called upon to provide him with employment, no matter how frantic his mother gets ...
Admin
Admin
Admin
We used to have to hand-roll our code to do something similar, back in the days of Old Fortran. What we ended up doing was maintaining a file of dates for each of the locales on which the times changed, and had a task to manually update them every year when we were provided the information as to what dates these would be. No big deal. We didn't need to keep track of what time of night the change would happen, because transactions from our customers did not happen overnight - they were strictly industries who worked industry hours.
We did this task alongside the task to update the file containing the dates each year on which a particular (and I mean "particular") client of ours decided that they would close their operation for the day (important for us to be able to calculate the number of "working days" in a time period).
Because ultimately your DST calculation program will only work as long as you have a mechanism for determining what the crucial dates are - which means someone's going to have to do something bodgey.
As for determining the precise time when a transaction happens, and comparing it with the exact time something else happens, if you datestamp all real-time data with GMT and then convert at UI side, you usually can't go wrong.
Admin
Considering how inherently fucked up DST is enforced around the world, it's really no wonder that almost noone ever gets it right.
I think Israel has one of the worst histories in this regard. Consider how fun it would be to work with historical data after having a look at how DST has been treated over time there: http://en.wikipedia.org/wiki/Israel_Summer_Time
Admin
http://darwinawards.com/darwin/darwin1999-38.html
Akismet, this is not spam.
Admin
It's gets fun when trying to schedule and event or whatever that takes place in the future on the other side of a DST changeover.
When the geeks do finally inherit the earth, DST will be the first thing to go.
Admin
Brasil daylight savings is the reverse of the Northern hemisphere and jumps at midnight. In Brazil, the third Sunday of October starts at 1:00am, not at midnight. "20-october-2013 12:15am" is not a valid timestamp in Brasil.
Causes some application issues when the application uses datetime types to store both dates (lacking a time portion) and timestamps (date and time). In the case where a datetime type is being used to only store a date value, most of the application I have seen attempt to set the value (behind the scenes) to having a time of "00:00", results in both java and oracle weirdness.
I hate DST.
Admin
Admin
The CTO's nephew should have left this one to the President's daughter.
Admin
Daylight Savings Time is the real WTF
Admin
Along with leap days, leap seconds, and time zones in general. UTC for everyone! Although if we really wanted to be inclusive we'd define the "epoch" as the Big Bang. A 64-bit time_t could easily handle number of seconds past the Big Bang epoch for the entire lifespan of the universe. Of course, a second is also a pretty arbitrary measurement. We should just count the number of Planck time units since the Big Bang, but we'll need to wait for a 256-bit time_t before doing that.
But then we're still going to get TDWTF stories about people rolling their own routines for time zone conversions between inertial and non-inertial frames of reference. Use the libraries, man! Some people never learn!
Admin
TRWTF is in fact "Daylight Savings Time". Daylight Saving Time. Saving is not plural.
Admin
Admin
And the third is Daylight Savings Time in the first place amirite or what?
EDIT: ok so everyone already posted that. Here's my software solution (assuming your organization hasn't figured out how to sync to a national clock base like every cellphone already does) -- hire a person whose sole responsibility is to watch for announced changes in DST wherever the messages/code are being shipped and manually fix it.
Admin
Hmmm... It seems nobody else noticed that time changes at 2 AM, not at midnight.
Admin
Admin
Oh, wait... Never mind.
Admin
Judaism follows a proleptic lunar calendar. The Islamic lunar calendar doesn't add the 13th leap month. Then, Iran has a Persian solar calendar that predates the advent of Islam. So, nobody in the Middle East can line up their holidays with the Roman (Christian) solar calendar.
I'm still waiting for the world to use the Mayan solar calendar. It's very accurate and we're way past removing our shoes to count to 20.
Admin
What A.Dev proposes is actaully wrong, at least in the UK and most of the rest of the world too. The time actually changes at 2am and not midnight.
I don't know about C# but you can get it right, in all years and all time zones, in C using the localtime(3) function, which includes a tm_idst for no extra charge, in addition to adjusting the time appropriately.
There is at least one 2am to 2am party when daylight saving ends and the clocks go back. Actually getting wrong in addition to not using the appropriate function is WTF.
Admin
Admin
Amen!
I do not know how many times I have had to cope with data where the time stamps have only been logged in normal text (causing wither an hour of no data or an hour of double data). Now try to do integration of data across DST changes...... (And yes, before you ask, I have tried for ages to have our data logging servers run only UTC, but the higher ups wants to be able to look at the data and compare with their watches Sigh)
Fortunately now we log the utime as well which none of the normal users knows what to do with and just ignores, but us doing the calculations at least do not have to bash our heads against the wall because some odd calculations barfed on DST changes...
Yours Yazeran
Plan: To go to Mars one day with a hammer
Admin
I know it's a WTF, deep down, but it could very well be that other timezones need not be considered. I know of two Arizona-based businesses, for example, that have happily spent 25+ years running various in-house software projects which do not account for DST, and likely never will.
That said, actually writing bugs like that make me twitch, but it could very well have been part of the spec (ha!) to not worry about DST. This year, I mean.
Admin
The Unix people had it right: Keep time in GMT, and the rest is a display problem.
When will people ever learn?
Admin
public static bool isDaylightSavingTime() { DateTime dd = DateTime.Now; if (dd <= new DateTime(2012, 10, 28, 00, 59, 59) || dd >= new DateTime(2013, 03, 31, 03, 00, 00)) { return true; } else if (dd > new DateTime(2012, 10, 28, 01, 59, 59) && dd < new DateTime(2013, 03, 31, 02, 00, 00)) { return false; } else { return FILE_NOT_FOUND; } }
There, I've fixed it.
Admin
Admin
Not quite.
It's not actually possibly to know if DST is active just by looking at the time during the Fall-Back hour between 1:00AM - 2:00AM. If you're going through that hour for the first time, then it's not DST. But then when you hit 2AM, you Fall Back to 1AM, and go through that hour for a second time, this time DST is active.
Admin
Leap days and leap seconds do have a purpose though. Leap days occur because the Earth doesn't take an integral number of days to orbit the sun. There's no reason it should, either since there is no relationship between the rotation velocity of the earth and the orbital velocity between it and the sun.
Leap seconds occur because the earth's rotation is measurably slowing down. Atomic clocks on earth are so accurate that the difference between a solar day and "real atomic time" is only going to get larger.
Timezones and daylight saving time, though, are completely arbitrary human constructs not bound by any physical measure of time and should therefore be eliminated. The only reason we have timezones is because prior to that, no one had "standard time" - every town set its clock to when the sun was directly overhead (== noon), and thus 2pm in one town can be 2:15pm at another town. All timezones did was create basically a standard of time for all - everyone was on the same time.
Even scientists can't agree on a standard reference time - there's plenty to choose from - UTC, UT0, UT1, ...
And don't forget that time moves slightly slower down here in the gravity well thanks to relativity. Enough so that the atomic clocks on GPS satellites have to compensate for the reduced gravity.
Admin
That code is just horrible. Like others said, you should use a library. The best approach is obviously:
Done!
Admin
No, this is the fix.
public static bool isDaylightSavingTime() { return false; // Works correctly in Arizona. }
Admin
That we can measure this at all is pretty awesome.
Admin
Daylight Wastings Time, duh.
Admin
In the weather industry, UTC (Coordinated Universal Time) is almost always used, eliminating the need to keep track of time zones and Daylight Saving.
However, leap years still need to be kept track of, which result in embarrassing gaffes in programs written by those who refuse to consider the existence of February 29th.
(I've heard the same is true in Astronomy circles.)
Admin
Come the rotation, the first thing to go will be UTC, because the difference between UTC and GMT is that UTC has leap seconds.
Admin
Works correctly in some parts of Arizona, unless you're on the some of the native land, in which case, it has DST, and then inside some parts of those areas, they revert back to no DST, and then inside a tiny bit of that land, it's DST again.
So much for simple rules.
Addendum (2013-09-09 20:55): In particular, see http://www.timeanddate.com/time/us/arizona-no-dst.html. The Navajo don't have DST, but the fully enclosed Hopi within the Navajo do. And as I recall, there's a tiny part of the Navajo inside the Hopi too, and so they don't.
Admin
Another WTF about this is that smartphones (Android/iOS) have the DST scheme from 2005-2012 implemented in code (despite the calendar insanity, it is relatively simple to compute the dates). So any phone that hasn't gotten an update in the last 6 months switched prematurely on Sunday. Many, many people woke up late (including some that had phones that didn't move back).
The real WTF is that the cell providers recommended changing phone's timezones to Athens, rather than pushing the timezone update through the network settings.
Admin
Problem is that the Navajo reservation covers parts of both Arizona and New Mexico. Arizona doesn't do DST, New Mexico does, and the administrative center for the rez is in Gallup, on the New Mexico side. So those parts of the rez in Arizona but dependent upon regular contact with Gallup sync with it and fiddle their clocks, while the parts whose relationship with non-Di'ne towns on the Arizona side is more important leave them alone.
Admin
Admin
Please don't blame me. Code written in the article is not mine.It was written against me.
Admin
I got bitten by DST when I wanted to set up a monthly webstats report. It's too long ago to remember the exact details, but during DST the log rollover day didn't match up with the webstats software reporting day, so that it would lose an hour from one end of the report and add it to the other as an extra "day" (which really messed up the report). Needless to say I kludged around it by limiting the report to the month as reported by the webstats software, so I actually failed to report on seven midnight hours per year.
Admin
For the "pics or it didn't happen" crowd: http://www.cntraveler.com/daily-traveler/2012/11/daylight-saving-donut-arizona-ken-jennings-maphead
Courtesy of the one and only Ken Jennings!