Handling daylight savings with standard time functions?

Discussion in 'C Programming' started by Generic Usenet Account, Jul 20, 2007.

  1. 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
    Generic Usenet Account, Jul 20, 2007
    #1
    1. Advertising

  2. Generic Usenet Account

    GeekBoy Guest

    "Generic Usenet Account" <> wrote in message
    news:...
    > 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?


    > Regards,
    > Anil
    >
    GeekBoy, Jul 20, 2007
    #2
    1. Advertising

  3. Generic Usenet Account

    Jim Barlow Guest

    GeekBoy wrote:
    > "Generic Usenet Account" <> wrote in message
    > news:...
    >> 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?
    >
    >
    >> Regards,
    >> Anil
    >>

    >
    >

    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.
    Jim Barlow, Jul 20, 2007
    #3
  4. Generic Usenet Account

    GeekBoy Guest

    "Jim Barlow" <> wrote in message
    news:...
    > GeekBoy wrote:
    >> "Generic Usenet Account" <> wrote in message
    >> news:...
    >>> 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?
    >>
    >>
    >>> Regards,
    >>> Anil
    >>>

    >>
    >>

    > 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.
    GeekBoy, Jul 20, 2007
    #4
  5. Generic Usenet Account

    Guest

    Generic Usenet Account <> wrote:
    >
    > 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
    , Jul 20, 2007
    #5
  6. "GeekBoy" <> writes:
    > "Jim Barlow" <> wrote in message
    > news:...

    [...]
    >> 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.


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

    --
    Keith Thompson (The_Other_Keith) <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."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Jul 20, 2007
    #6
  7. Generic Usenet Account

    Tim Slattery Guest

    "GeekBoy" <> wrote:


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

    --
    Tim Slattery

    http://members.cox.net/slatteryt
    Tim Slattery, Jul 23, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    1
    Views:
    1,465
    Ryan Ternier
    Oct 14, 2005
  2. Polaris431
    Replies:
    4
    Views:
    487
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    May 28, 2007
  3. Generic Usenet Account
    Replies:
    6
    Views:
    344
    Tim Slattery
    Jul 23, 2007
  4. DiAvOl

    About time functions and daylight savings

    DiAvOl, Nov 8, 2007, in forum: C Programming
    Replies:
    6
    Views:
    412
    Tor Rustad
    Nov 9, 2007
  5. Washington Ratso
    Replies:
    1
    Views:
    59
    Chris “Kwpolska†Warrick
    Apr 3, 2014
Loading...

Share This Page