2007 daylight saving time issues with struct tm member tm_isdst

R

Robm

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
 
V

Vladimir S. Oka

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
 
K

Keith Thompson

Robm said:
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.
 
R

Rod Pemberton

Robm said:
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
 
J

Jordan Abel

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

Chris Torek

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

Rod Pemberton

Chris Torek said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top