Handling daylight savings with standard time functions?

  • Thread starter Generic Usenet Account
  • Start date
G

Generic Usenet Account

Hi,

Is there any way to make time-of-day adjustments for daylight savings
using only standard time functions? We have a program that executes
daily at a fixed time of day. After daylight savings happens, the
time-of-day alignment is lost. For example, if the daily task gets
kicked in at 9 p.m. every evening, after daylight savings ends in
fall, the task is shown as kicking in at 8 p.m. Similarly, if the
daily task gets kicked in at 4 a.m. every morning, after daylight
savings starts in spring, the task is shown as kicking in at 5 a.m.

I tried a few things, including explicitly advancing the day field in
the struct tm structure (sample source code posted to comp.sources.d),
without messing with the seconds, minutes and hours fields. However,
even that is not working. It appears that mktime() is not smart
enough to detect that daylight savings has started/ended.

Any help will be appreciated.

Regards,
Anil
 
G

GeekBoy

Generic Usenet Account said:
Hi,

Is there any way to make time-of-day adjustments for daylight savings
using only standard time functions? We have a program that executes
daily at a fixed time of day. After daylight savings happens, the
time-of-day alignment is lost. For example, if the daily task gets
kicked in at 9 p.m. every evening, after daylight savings ends in
fall, the task is shown as kicking in at 8 p.m. Similarly, if the
daily task gets kicked in at 4 a.m. every morning, after daylight
savings starts in spring, the task is shown as kicking in at 5 a.m.

I tried a few things, including explicitly advancing the day field in
the struct tm structure (sample source code posted to comp.sources.d),
without messing with the seconds, minutes and hours fields. However,
even that is not working. It appears that mktime() is not smart
enough to detect that daylight savings has started/ended.

Any help will be appreciated.


Why not just use the system time and let it worry about the correct time?
 
J

Jim Barlow

GeekBoy said:
Why not just use the system time and let it worry about the correct time?
I notice the US Congress has changed the beginning and end of DST in an
arbitrary and capricious manner this year. So I think system time.
 
G

GeekBoy

Jim Barlow said:
I notice the US Congress has changed the beginning and end of DST in an
arbitrary and capricious manner this year. So I think system time.

Actually it was Bush via executive order instructing the Excutive Branch
offices to start using the new time change.
Everyone else (execpt Arizona) just followed along.
 
L

lawrence.jones

Generic Usenet Account said:
I tried a few things, including explicitly advancing the day field in
the struct tm structure (sample source code posted to comp.sources.d),
without messing with the seconds, minutes and hours fields. However,
even that is not working. It appears that mktime() is not smart
enough to detect that daylight savings has started/ended.

Did you set the isdst field to some negative value to tell mktime() that
you wanted it to try to figure it out?

-Larry Jones

Things are never quite as scary when you've got a best friend. -- Calvin
 
K

Keith Thompson

GeekBoy said:
Actually it was Bush via executive order instructing the Excutive Branch
offices to start using the new time change.
Everyone else (execpt Arizona) just followed along.

<OT>
Incorrect. The change in the US was mandated by the Energy Policy Act
of 2005. (There may have been an executive order to implement the
law, I suppose, but I don't see why it would be necessary.)
</OT>

Usually the underlying operating system is responsible for keeping
track of these things. Typically patches are distributed to account
for rule changes.

The tm_isdst member of struct tm *should* tell you whether Daylight
Saving Time is in effect, or at least whether the system knows one way
or the other. C99 7.23.1p4:

The value of tm_isdst is positive if Daylight Saving Time is in
effect, zero if Daylight Saving Time is not in effect, and
negative if the information is not available.

If tm_isdst gives you an incorrect non-negative result, then there's a
problem in the system; correcting any such problem is beyond the scope
of this newsgroup.
 
T

Tim Slattery

Actually it was Bush via executive order instructing the Excutive Branch
offices to start using the new time change.
Everyone else (execpt Arizona) just followed along.

No, it was an act of Congress. Arizona has never observed DST, with
the exception of the Navajo reservation in the Northeast corner of the
state.

And Hawaii and Puerto Rico don't observe DST since they are in the
tropics and the length of day and night doesn't vary much through the
year. I assume Guam and other tropical territories do the same.

Then there's Indiana. The Eastern/Central time zone boundary divides
the state, and some counties use DST and some don't. I understand this
has been simplified somewhat recently, but don't know details.
 

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

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,734
Latest member
manin

Latest Threads

Top