Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > 2007 daylight saving time issues with struct tm member tm_isdst

Reply
Thread Tools

2007 daylight saving time issues with struct tm member tm_isdst

 
 
Robm
Guest
Posts: n/a
 
      03-24-2006
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


 
Reply With Quote
 
 
 
 
Vladimir S. Oka
Guest
Posts: n/a
 
      03-24-2006
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

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      03-24-2006
"Robm" <(E-Mail Removed)> 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.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
Rod Pemberton
Guest
Posts: n/a
 
      03-25-2006

"Robm" <(E-Mail Removed)> wrote in message
news:jjUUf.10032$(E-Mail Removed). ..
> 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



 
Reply With Quote
 
Jordan Abel
Guest
Posts: n/a
 
      03-25-2006
On 2006-03-25, Rod Pemberton <(E-Mail Removed)> 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.
 
Reply With Quote
 
Chris Torek
Guest
Posts: n/a
 
      03-25-2006
In article <e0376g$b984$(E-Mail Removed)>
Rod Pemberton <(E-Mail Removed)> 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 (4039.22'N, 11150.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.
 
Reply With Quote
 
Rod Pemberton
Guest
Posts: n/a
 
      03-25-2006

"Chris Torek" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <e0376g$b984$(E-Mail Removed)>
> Rod Pemberton <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How tm_isdst affects "%Z" specifier in function strftime()? Hill Pang C Programming 5 12-19-2012 02:34 PM
Dates, time zones,daylight saving time Harlan Messinger ASP .Net 1 04-15-2010 11:27 PM
U.S. Daylight Saving Time Changes in 2007 Serguei.Goumeniouk@cibc.ca Java 2 01-03-2007 06:59 AM
Daylight Saving time: How to identify if a given time is invalid? Pranav Kantawala Java 5 02-25-2004 06:28 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM



Advertisments