2007 daylight saving time issues with struct tm member tm_isdst

Discussion in 'C Programming' started by Robm, Mar 24, 2006.

  1. Robm

    Robm Guest

    Since googling this issue only brings up the April fool's problem, which was
    solved years ago, I hope that somebody can help me with this. I have a large
    vc++/mfc application which needs to know when DST is in effect. This has
    been working fine for years, but I am worried about the upcoming change in
    2007 in the US, which will be followed by a number of Canadian provices
    (where my application is used). The function that I use is very simple, as
    shown below, but I doubt very much that this will still work in 2007. I
    especially doubt that this will still work for both NB and NS, two provices
    in the same timezone, but NB will follow the US, while NS may not.

    BOOL CPortView::isdst(time_t tim)
    {
    int ret=0;
    struct tm *tmp;
    if(_daylight){
    tmp=localtime(&tim);
    ret=tmp->tm_isdst;
    }
    return(ret?TRUE:FALSE);
    }

    In the Windows OS, you can pick a timezone, and you can set if DST is to be
    used, but you can't set the rules for it. So how is this supposed to work?

    Any and all comments are appreciated. Apologies if this is not the proper
    newsgroup.

    Rob M
    Robm, Mar 24, 2006
    #1
    1. Advertising

  2. Robm opined:

    Followups set...

    > Since googling this issue only brings up the April fool's problem,
    > which was solved years ago, I hope that somebody can help me with
    > this. I have a large vc++/mfc application which needs to know when
    > DST is in effect. This has been working fine for years, but I am
    > worried about the upcoming change in 2007 in the US, which will be
    > followed by a number of Canadian provices (where my application is
    > used). The function that I use is very simple, as shown below, but I
    > doubt very much that this will still work in 2007. I especially doubt
    > that this will still work for both NB and NS, two provices in the
    > same timezone, but NB will follow the US, while NS may not.
    >
    > BOOL CPortView::isdst(time_t tim)
    > {
    > int ret=0;
    > struct tm *tmp;
    > if(_daylight){
    > tmp=localtime(&tim);
    > ret=tmp->tm_isdst;
    > }
    > return(ret?TRUE:FALSE);
    > }
    >
    > In the Windows OS, you can pick a timezone, and you can set if DST is
    > to be used, but you can't set the rules for it. So how is this
    > supposed to work?
    >
    > Any and all comments are appreciated. Apologies if this is not the
    > proper newsgroup.
    >
    > Rob M


    C++ questions are never topical in comp.lang.c
    Other two groups sound about right.

    --
    BR, Vladimir

    Every day people are straying away from the church and going back to
    God.
    -- Lenny Bruce
    Vladimir S. Oka, Mar 24, 2006
    #2
    1. Advertising

  3. "Robm" <> writes:
    > Since googling this issue only brings up the April fool's problem, which was
    > solved years ago, I hope that somebody can help me with this. I have a large
    > vc++/mfc application which needs to know when DST is in effect. This has
    > been working fine for years, but I am worried about the upcoming change in
    > 2007 in the US, which will be followed by a number of Canadian provices
    > (where my application is used). The function that I use is very simple, as
    > shown below, but I doubt very much that this will still work in 2007. I
    > especially doubt that this will still work for both NB and NS, two provices
    > in the same timezone, but NB will follow the US, while NS may not.
    >
    > BOOL CPortView::isdst(time_t tim)
    > {
    > int ret=0;
    > struct tm *tmp;
    > if(_daylight){
    > tmp=localtime(&tim);
    > ret=tmp->tm_isdst;
    > }
    > return(ret?TRUE:FALSE);
    > }
    >
    > In the Windows OS, you can pick a timezone, and you can set if DST is to be
    > used, but you can't set the rules for it. So how is this supposed to work?
    >
    > Any and all comments are appreciated. Apologies if this is not the proper
    > newsgroup.


    As Vladimir mentioned, you've posted C++ code to comp.lang.c.
    However, your actual problem seems to be related to the common subset
    of C and C++ (specifically the localtime function).

    The tm_isdst member of a struct tm set by a call to localtime() is
    required to be positive if DST is in effect, 0 if it isn't, or
    negative if the information isn't available. It's up to the
    implementation to get this right. If your implementation fails to do
    so, it's a bug in your implementation, not a C language issue.

    I haven't touched the Newsgroups header, but please choose carefully
    if you post a followup; if you're going to discuss Windows issues,
    please drop comp.lang.c.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Mar 24, 2006
    #3
  4. "Robm" <> wrote in message
    news:jjUUf.10032$...
    > Since googling this issue only brings up the April fool's problem, which

    was
    > solved years ago, I hope that somebody can help me with this. I have a

    large
    > vc++/mfc application which needs to know when DST is in effect. This has
    > been working fine for years, but I am worried about the upcoming change in
    > 2007 in the US, which will be followed by a number of Canadian provices
    > (where my application is used). The function that I use is very simple, as
    > shown below, but I doubt very much that this will still work in 2007. I
    > especially doubt that this will still work for both NB and NS, two

    provices
    > in the same timezone, but NB will follow the US, while NS may not.
    >


    Depending on your C implementation or OS, you may not need to do anything.
    If the C implementation determines DST, they may correct the problem. If
    the OS sets the DST (and the C implementation just reads it), the automatic
    change by the OS or a change by the system administrator will correctly set
    DST for you.

    If not, it's fairly easy to write your own is_dst() function. I don't know
    C++. In the past, I've written functions to do this in C and PL/I. You
    just need to determine if the date in question is between two other dates.
    One method is to encode the start, end, and current dates as seconds making
    sure the conversion was timezone independent (i.e., using GMT/UTC, or Zulu
    time). Then, you compare to the current date as seconds. Another method is
    to elements of the time structures to compare each month and day, etc.,
    respectively which should only take a couple of if's and maybe a switch.

    The two dates of the year which represent the start and end of US Daylight
    Saving Time are defined by US Federal law. They are as follows:

    before 1965 no Daylight Saving Time in US
    1966-1985 Last Sunday of April to Last Sunday of October
    1986-2006 First Sunday of April to Last Sunday of October
    2007- Second Sunday of March to First Sunday of November

    (The 2007 and on law was passed, but I believe it is still being reviewed by
    Congress...)


    Rod Pemberton
    Rod Pemberton, Mar 25, 2006
    #4
  5. Robm

    Jordan Abel Guest

    On 2006-03-25, Rod Pemberton <> wrote:
    >
    > If not, it's fairly easy to write your own is_dst() function. I don't
    > know C++. In the past, I've written functions to do this in C and
    > PL/I. You just need to determine if the date in question is between
    > two other dates. One method is to encode the start, end, and current
    > dates as seconds making sure the conversion was timezone independent
    > (i.e., using GMT/UTC, or Zulu time).


    Don't forget that the transition takes place at 02:00 standard time,
    which means if you're encoding it in terms of UTC you need a different
    date for each timezone, probably more trouble than it's worth.
    Jordan Abel, Mar 25, 2006
    #5
  6. Robm

    Chris Torek Guest

    In article <e0376g$b984$>
    Rod Pemberton <> wrote:
    >The two dates of the year which represent the start and end of US Daylight
    >Saving Time are defined by US Federal law. They are as follows:
    >
    >before 1965 no Daylight Saving Time in US
    >1966-1985 Last Sunday of April to Last Sunday of October
    >1986-2006 First Sunday of April to Last Sunday of October
    >2007- Second Sunday of March to First Sunday of November


    This is ... woefully incomplete. The above is merely the current
    Federal standard for the United States. Various parts of the US
    do not observe DST at all (most of Arizona in particular). See,
    e.g., <http://nationalatlas.gov/mld/timeznp.html>; note the odd
    colors for AZ and IN.

    Daylight Saving Time was observed in much of the US during WW1
    (in 1918 and 1919). It was then observed in various cities
    sporadically until WW2, when it was revived nationwide as "War
    Time". After 1945 it reverted to local control until 1966, as
    noted above.

    DST has also been used in other countries. A reasonably-complete
    "computer DST database" (the "zoneinfo database") can be found
    by starting at <http://www.twinsun.com/tz/tz-link.html>.
    --
    In-Real-Life: Chris Torek, Wind River Systems
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it http://web.torek.net/torek/index.html
    Reading email is like searching for food in the garbage, thanks to spammers.
    Chris Torek, Mar 25, 2006
    #6
  7. "Chris Torek" <> wrote in message
    news:...
    > In article <e0376g$b984$>
    > Rod Pemberton <> wrote:
    > >The two dates of the year which represent the start and end of US

    Daylight
    > >Saving Time are defined by US Federal law. They are as follows:
    > >
    > >before 1965 no Daylight Saving Time in US
    > >1966-1985 Last Sunday of April to Last Sunday of October
    > >1986-2006 First Sunday of April to Last Sunday of October
    > >2007- Second Sunday of March to First Sunday of November

    >
    > This is ... woefully incomplete. The above is merely the current
    > Federal standard for the United States. Various parts of the US
    > do not observe DST at all (most of Arizona in particular). See,
    > e.g., <http://nationalatlas.gov/mld/timeznp.html>; note the odd
    > colors for AZ and IN.
    >


    True. I listed US laws, but he was asking about DST for Canada. It should
    also say "before 1966".

    > Daylight Saving Time was observed in much of the US during WW1
    > (in 1918 and 1919). It was then observed in various cities
    > sporadically until WW2, when it was revived nationwide as "War
    > Time". After 1945 it reverted to local control until 1966, as
    > noted above.


    Both, you and I "forgot" to list the exceptions for the US for 1974-1975:
    1974 First Sunday of January to Last Sunday of October
    1975 Last Sunday of February to Last Sunday of October

    > DST has also been used in other countries. A reasonably-complete
    > "computer DST database" (the "zoneinfo database") can be found
    > by starting at <http://www.twinsun.com/tz/tz-link.html>.


    I'll just refer everyone here as a starting point for more history:
    http://en.wikipedia.org/wiki/Daylight_saving_time


    Rod Pemberton
    Rod Pemberton, Mar 25, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pranav Kantawala
    Replies:
    5
    Views:
    744
    P.Hill
    Feb 25, 2004
  2. Filip Lyncker
    Replies:
    3
    Views:
    746
    Karl Heinz Buchegger
    Apr 5, 2005
  3. Replies:
    2
    Views:
    305
    John O'Conner
    Jan 3, 2007
  4. Harlan Messinger

    Dates, time zones,daylight saving time

    Harlan Messinger, Apr 15, 2010, in forum: ASP .Net
    Replies:
    1
    Views:
    1,011
    Eric Isaacs
    Apr 16, 2010
  5. Hill Pang
    Replies:
    5
    Views:
    342
    Ike Naar
    Dec 19, 2012
Loading...

Share This Page