473,223 Members | 1,687 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,223 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 8807
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 (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.
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 =...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.