mktime and DST.

Discussion in 'C Programming' started by Gore, Oct 7, 2003.

  1. Gore

    Gore Guest

    hi,

    I tried the following piece of code
    long sec = -1;
    struct tm date;
    date.tm_year = 1995 - 1900;
    date.tm_mon = 7 - 1;
    date.tm_mday = 16;
    date.tm_hour = 0;
    date.tm_min = 0;
    date.tm_sec = 0;

    date.tm_isdst = 0;

    sec = mktime(&date);

    The value returned by mktime when tm_isdst is set to 0 is different
    from the value returned by mktime when tm_isdst is set to -1 or 1. Why
    is that?
    The date given is 16th July 1995 00:00:00.

    The compiler is used MSVC 6.0 Service pack 5.
    Observed the same behavious on Sun Solaris.
    My machine has the us-pacific time set ( GMT - 8 Hours ).

    Mihir
     
    Gore, Oct 7, 2003
    #1
    1. Advertisements

  2. Gore

    Richard Bos Guest

    (Gore) wrote:

    > I tried the following piece of code
    > long sec = -1;
    > struct tm date;
    > date.tm_year = 1995 - 1900;
    > date.tm_mon = 7 - 1;
    > date.tm_mday = 16;
    > date.tm_hour = 0;
    > date.tm_min = 0;
    > date.tm_sec = 0;
    >
    > date.tm_isdst = 0;
    >
    > sec = mktime(&date);
    >
    > The value returned by mktime when tm_isdst is set to 0 is different
    > from the value returned by mktime when tm_isdst is set to -1 or 1. Why
    > is that?
    > The date given is 16th July 1995 00:00:00.


    Because your system thinks that DST is in place at that date and time in
    your time zone. It certainly is in my timezone at that date.
    tm_isdtd==0 means "I know DST is not in effect. Compute this timestamp
    assuming that it isn't." tm_isdst>0 means "I know DST is in effect.
    Compute this timestamp assuming that it is." tm_isdst<0 means "I don't
    know whether DST is in effect now. Please determine this for me, then
    compute this timestamp with the determined DST setting."
    If the computer thinks DST is in effect, then yes, tm_isdst==-1 would
    give the same result as tm_isdst==1. Had it thought DST were not in
    effect, tm_isdst==-1 would give the same result as tm_isdtd==0.

    Richard
     
    Richard Bos, Oct 7, 2003
    #2
    1. Advertisements

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

    mktime segfault

    Florian Quetting, Dec 31, 2004, in forum: C++
    Replies:
    2
    Views:
    669
    Florian Quetting
    Dec 31, 2004
  2. Rajmohan

    GMT equivalent of mktime

    Rajmohan, Jul 14, 2003, in forum: C Programming
    Replies:
    1
    Views:
    1,065
    Mark McIntyre
    Jul 14, 2003
  3. reppisch

    time() sleep() and dst

    reppisch, Oct 27, 2006, in forum: C Programming
    Replies:
    14
    Views:
    665
    Random832
    Nov 20, 2006
  4. W. eWatson

    DST and datetime

    W. eWatson, Dec 30, 2009, in forum: Python
    Replies:
    1
    Views:
    380
    Lawrence D'Oliveiro
    Jan 4, 2010
  5. Shankar

    snprintf with same src and dst

    Shankar, Dec 7, 2010, in forum: C Programming
    Replies:
    4
    Views:
    1,134
    Ike Naar
    Dec 8, 2010
  6. El Gato

    Ruby and DST change

    El Gato, Feb 6, 2007, in forum: Ruby
    Replies:
    1
    Views:
    158
    Daniel Berger
    Feb 6, 2007
  7. mhearne808[insert-at-sign-here]gmail[insert-dot-he

    localtime and mktime

    mhearne808[insert-at-sign-here]gmail[insert-dot-he, Jun 28, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    299
    Peter J. Holzer
    Jul 1, 2007
  8. Replies:
    0
    Views:
    241
Loading...