473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

2007 daylight saving time issues with struct tm member tm_isdst

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
Mar 24 '06 #1
6 8810
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

Mar 24 '06 #2
"Robm" <ro**@rkmengineering.com> 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) ks***@mib.org <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.
Mar 24 '06 #3

"Robm" <ro**@rkmengineering.com> wrote in message
news:jj********************@news20.bellglobal.com. ..
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

Mar 25 '06 #4
On 2006-03-25, Rod Pemberton <do*********@sorry.bitbuck.cmm> 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.
Mar 25 '06 #5
In article <e0***********@news3.infoave.net>
Rod Pemberton <do*********@sorry.bitbuck.cmm> 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.
Mar 25 '06 #6

"Chris Torek" <no****@torek.net> wrote in message
news:e0********@news4.newsguy.com...
In article <e0***********@news3.infoave.net>
Rod Pemberton <do*********@sorry.bitbuck.cmm> wrote:
The two dates of the year which represent the start and end of US DaylightSaving 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
Mar 25 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Qvx | last post by:
Hello, I'we written a simple web deployment program which scans for the changes made to local copy of web site. Changed files are than packaged into a zip file and deployed to web server. Now...
3
by: zmau | last post by:
Hi, I would like to know if Daylight Saving time is ON, and then calculate the time (i.e. how many hours difference due to the Daylight Saving time). I need it because I am getting the time...
14
by: Amitabh Deepak | last post by:
Is there any way to check whether daylight saving is enabled on a linux machine?
1
by: Drew | last post by:
Is there a way to check if it is daylight savings or not via c#? I have heard you can use System.Globalization? Thanks - Drew
7
by: Brett Edman | last post by:
I created a UTC clock using this: UTCTime = MyTime.ToUniversalTime() Now that we've turned the clocks ahead 1 hour for daylight savings time, the clock is reporting the wrong UTC time. It is...
6
by: sugapablo | last post by:
I have an old machine running Mandrake 9.2 and PHP 4.3.1 hosting several websites. With the coming changes to daylight savings time in March 2007, what are my options in correcting the current...
27
by: RobG | last post by:
I was investigating a function to determine whether daylight saving was being observed on a particular date (given the platform's regional settings) and came across a suggestion at merlyn.com to...
3
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I have a web application that will be hosted on servers with timezones configured to EST with daylight saving. My application takes an XML datafeed that contains times in GMT (also with...
0
by: Fabio Durieux Lopes | last post by:
Hi, I'm trying to execute some operations based on a file's time. The file's time is actually the file's name (e.g. FILE1_20080326170558). So I do this: fileTimeInSecs =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.