471,874 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

daylight saving time

Hi,

I would like to determine whether at a certain time point in time the
daylight savings time is in effect. This means such a logic should show
that today (16-Nov-2007) no daylight savings time (or European summertime)
is in effect, but at 1-Aug-2007 it is.

Thanks for your help

Bernhard Hoyler
Nov 16 '07 #1
3 3828
bernhard Hoyler wrote:
I would like to determine whether at a certain time point in time the
daylight savings time is in effect. This means such a logic should
show that today (16-Nov-2007) no daylight savings time (or European
summertime) is in effect, but at 1-Aug-2007 it is.
The simplest way would be to have our own table of correct values and
compare against those ranges. You'd have to keep historical data since
the laws about daylight saving were introduced in different places at
different times. You also need to account for the place where the
program is running since some locales don't support daylight saving
times (like Arizona or parts of Indiana, IIRC). Also, the times at
which DST goes in effect are different in different countries.

OTOH you could of course rely on the member of the 'tm' struct, called
tm_isdst. Google for it, I am sure there are example of how to use it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 16 '07 #2
Victor Bazarov wrote:
bernhard Hoyler wrote:
>I would like to determine whether at a certain time point in time the
daylight savings time is in effect. This means such a logic should
show that today (16-Nov-2007) no daylight savings time (or European
summertime) is in effect, but at 1-Aug-2007 it is.

The simplest way would be to have our own table of correct values and
compare against those ranges.
No, that's not the simplest way.

The simplest way is to use std::time() and then std::localtime().
The latter returns a struct tm, which contains the member variable
tm_isdst which tells the info he is looking for.

Unless my manpage is wrong, this should even be standard.

CONFORMING TO
SVr4, POSIX.1-2001, 4.3BSD, C89, C99.
Nov 16 '07 #3
Juha Nieminen wrote:
Victor Bazarov wrote:
>bernhard Hoyler wrote:
>>I would like to determine whether at a certain time point in time
the daylight savings time is in effect. This means such a logic
should show that today (16-Nov-2007) no daylight savings time (or
European summertime) is in effect, but at 1-Aug-2007 it is.

The simplest way would be to have our own table of correct values and
compare against those ranges.

No, that's not the simplest way.

The simplest way is to use std::time() and then std::localtime().
The latter returns a struct tm, which contains the member variable
tm_isdst which tells the info he is looking for.

Unless my manpage is wrong, this should even be standard.

CONFORMING TO
SVr4, POSIX.1-2001, 4.3BSD, C89, C99.
Are you sure that those functions and the struct provide the correct
functionality for finding out, say, whether the WWI ended during DST
or not? What if I enter the DOB of the Pope, will I know if he was
born during European summertime?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 16 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Amitabh Deepak | last post: by
1 post views Thread by Drew | last post: by
7 posts views Thread by Brett Edman | last post: by
reply views Thread by Chirag Shukla | last post: by
1 post views Thread by maflatoun | last post: by
1 post views Thread by maflatoun | last post: by
1 post views Thread by luke_airig | last post: by
27 posts views Thread by RobG | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

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.