• QJo (unregistered)

    The frist WTF is of course being a nephew.

  • RFoxmich (unregistered)

    The second letting the CTO hire his own nephew

  • (cs) in reply to RFoxmich

    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.

  • (cs)

    Was the nephew planning to edit this code every year, as part of some sort of job security scheme?

  • (cs)

    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.

  • JimmyCrackedCorn (unregistered)

    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

  • Hasse (unregistered) in reply to Roby McAndrew
    Roby McAndrew:
    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.

    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

  • Kasper (unregistered) in reply to Roby McAndrew
    Roby McAndrew:
    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.
    He did use DateTime. Using the libraries is not enough, you need to also use them appropriately.
  • csrster (unregistered)
    public static bool isDaylightSavingTime() {
      DateTime dd = DateTime.Now;
      return (dd <= new DateTime(2012, 10, 27, 23, 59, 59) || dd >= new DateTime(2013, 03, 30, 23, 59, 59));
    }
    

    There you go. The real WTF fixed.

  • QJo (unregistered)

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

  • Pero perić (unregistered) in reply to Kasper
    Kasper:
    Roby McAndrew:
    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.
    He did use DateTime. Using the libraries is not enough, you need to also use them appropriately.
    Perhaps A. Dev should rewrite it using Noda Time library.
  • (cs) in reply to JimmyCrackedCorn
    JimmyCrackedCorn:
    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

    Two out of three ain't bad. The middle one is Objective C, not C#.

  • QJo (unregistered)

    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.

  • Oslo (unregistered)

    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

  • Duckman (unregistered) in reply to Oslo
    Oslo:
    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
    Hey, don't diss Israeli DST. It can result in interesting news stories:

    http://darwinawards.com/darwin/darwin1999-38.html

    Akismet, this is not spam.

  • mizchief (unregistered)

    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.

  • rob (unregistered)

    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.

  • (cs) in reply to Oslo
    Oslo:
    I think Israel has one of the worst histories in this regard.
    No, the worst is Argentina. There's one district there that just can't leave the rules alone; they just keep on changing them arbitrarily, causing new sets of DST rules to have to be issued multiple times a year. Fuck. (I'm guessing that the rest of Argentina also thinks that they're douches, but I don't know for sure.)
  • Stabbitha (unregistered)

    The CTO's nephew should have left this one to the President's daughter.

  • AverageJon (unregistered)

    Daylight Savings Time is the real WTF

  • Chelloveck (unregistered) in reply to mizchief
    mizchief:
    When the geeks do finally inherit the earth, DST will be the first thing to go.

    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!

  • Paula (unregistered)

    TRWTF is in fact "Daylight Savings Time". Daylight Saving Time. Saving is not plural.

  • (cs)
    his plan was to outsource the rest of the development of the application in order to ensure good-quality code.
    Run.
  • (cs) in reply to RFoxmich
    RFoxmich:
    The second letting the CTO hire his own nephew

    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.

  • RobR (unregistered)

    Hmmm... It seems nobody else noticed that time changes at 2 AM, not at midnight.

  • (cs) in reply to RobR
    RobR:
    Hmmm... It seems nobody else noticed that time changes at 2 AM, not at midnight.
    I know! And also that Lotus Notes is not relational.
  • Bananas (unregistered)
    The CTO told management that his plan was to outsource the rest of the development of the application in order to ensure good-quality code.
    Given that the CTO hired his nephew in the first place, it's not hard to believe that the CTO actually believed this. But that he was able to sell it to management?

    Oh, wait... Never mind.

  • Tasty (unregistered) in reply to Duckman
    Duckman:
    Oslo:
    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
    Hey, don't diss Israeli DST. It can result in interesting news stories:

    http://darwinawards.com/darwin/darwin1999-38.html

    Akismet, this is not spam.

    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.

  • Duncan Simpson (unregistered) in reply to JimmyCrackedCorn

    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.

  • Peter (unregistered) in reply to RobR
    RobR:
    Hmmm... It seems nobody else noticed that time changes at 2 AM, not at midnight.
    Nobody?
    ip-guru:
    And of course daylight savings times do not change at midnight (at least in the UK they change at 2am, Winter & 1am, Summer)
  • Yazeran (unregistered) in reply to AverageJon
    AverageJon:
    Daylight Savings Time is the real WTF

    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

  • BillR (unregistered)

    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.

  • (cs)

    The Unix people had it right: Keep time in GMT, and the rest is a display problem.

    When will people ever learn?

  • anonymous (unregistered)

    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.

  • (cs) in reply to AverageJon
    AverageJon:
    Daylight Savings Time is the real WTF
    And if not that, how about that it's DST for more of the year now than it is "standard" time. Those places still backward enough to want to fiddle with the clocks should call the summer thing standard and what they have in the winter "Daylight Wasting Time".
  • Maltz (unregistered) in reply to anonymous
    anonymous:
    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.

    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.

  • Worf (unregistered) in reply to Chelloveck
    Chelloveck:
    mizchief:
    When the geeks do finally inherit the earth, DST will be the first thing to go.

    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!

    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.

  • Anonypony (unregistered)

    That code is just horrible. Like others said, you should use a library. The best approach is obviously:

    public static bool isDaylightSavingTime() {
      var s = new System.Net.WebClient().DownloadString("https://www.google.com/search?q=daylight+saving+time");
      return DateTime.Now >= GetStartDate(s) || DateTime.Now <= GetEndDate(s);
    }
    

    Done!

  • Tristram (unregistered) in reply to csrster

    No, this is the fix.

    public static bool isDaylightSavingTime() { return false; // Works correctly in Arizona. }

  • (cs) in reply to Worf
    Worf:
    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.
    Actually, part of the reason they occur is that there is some natural randomness in the length of year, mostly due to complex interactions with tides and possibly also other planets in the solar system. (Blame Jupiter. It's big enough; it can take it.) The effect is small, but gradually builds up until it gets as large as a second.

    That we can measure this at all is pretty awesome.

  • Gary (unregistered) in reply to da Doctah
    da Doctah:
    AverageJon:
    Daylight Savings Time is the real WTF
    And if not that, how about that it's DST for more of the year now than it is "standard" time. Those places still backward enough to want to fiddle with the clocks should call the summer thing standard and what they have in the winter "Daylight Wasting Time".

    Daylight Wastings Time, duh.

  • J-L (unregistered)

    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.)

  • Norman Diamond (unregistered) in reply to Worf
    Worf:
    Chelloveck:
    mizchief:
    When the geeks do finally inherit the earth, DST will be the first thing to go.
    Along with leap days, leap seconds, and time zones in general. UTC for everyone!
    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.

    Leap seconds occur because the earth's rotation is measurably slowing down.

    Come the revolution, the first thing to go will be a rotation.

    Come the rotation, the first thing to go will be UTC, because the difference between UTC and GMT is that UTC has leap seconds.

  • (cs) in reply to Tristram
    Tristram:
    No, this is the fix.

    public static bool isDaylightSavingTime() { return false; // Works correctly in Arizona. }

    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.

  • Steven (unregistered) in reply to Oslo

    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.

  • (cs) in reply to realmerlyn
    realmerlyn:
    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.

    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.

  • (cs) in reply to Gary
    Gary:
    da Doctah:
    AverageJon:
    Daylight Savings Time is the real WTF
    And if not that, how about that it's DST for more of the year now than it is "standard" time. Those places still backward enough to want to fiddle with the clocks should call the summer thing standard and what they have in the winter "Daylight Wasting Time".

    Daylight Wastings Time, duh.

    Thanks youse fors settings mes straights.

  • A.Dev (unregistered) in reply to Duncan Simpson
    Duncan Simpson:
    What A.Dev proposes is actaully wrong,
    Proposes? I did not propose this code!

    Please don't blame me. Code written in the article is not mine.It was written against me.

  • Neil (unregistered)

    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.

  • (cs) in reply to da Doctah
    da Doctah:
    realmerlyn:
    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.

    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.

    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!

Leave a comment on “Daylight Failing Time”

Log In or post as a guest

Replying to comment #:

« Return to Article