ctime()/mktime() question

ctime()/mktime() question

Post by M. J. Saltzm » Sat, 21 Mar 1998 04:00:00



OK, if I understand the man pages, the following program should
print

        Wed Jul  1 08:30:00 1998

But it doesn't.  Instead it prints

        Wed Jul  1 09:30:00 1998

This occurs under Linux 2.0.32, Solaris 2.5.1, SunOs.  A similar program
in Perl produces a similar result.  What am I failing to do or understand?

Thanks in advace for any advice.  E-mail is fine, and I'll summarize.

        #include <time.h>
        #include <stdio.h>

        int main(void)
        {
          struct tm t = { 0,    /* seconds */
                         30,    /* minutes */
                          8,    /* hours since midnight */
                          1,    /* day of month */
                          6,    /* months since January */
                         98,    /* years since 1900 */
                          0,    /* day of week (reset by mktime) */
                          0,    /* day of year (reset by mktime) */
                          0};   /* daylight/standard switch */
                                /* --changing has no effect */
          time_t    c;

          c = mktime(&t);
          printf("%s\n", ctime(&c));

          return 0;
        }

--
                Matthew Saltzman
                Clemson University Math Sciences

 
 
 

ctime()/mktime() question

Post by M. J. Saltzm » Sun, 22 Mar 1998 04:00:00



>OK, if I understand the man pages, the following program should
>print
>    Wed Jul  1 08:30:00 1998
>But it doesn't.  Instead it prints
>    Wed Jul  1 09:30:00 1998
>This occurs under Linux 2.0.32, Solaris 2.5.1, SunOs.  A similar program
>in Perl produces a similar result.  What am I failing to do or understand?

Aha!  I misunderstood the role of isdst (the last field in the struct tm).
First, it *does* have an effect, just one that is revealed only if
thoroughly tested.

If you want the conversion to be done without paying attention to
whether DST is in effect, then isdst should be negative.  If the date
you are converting is a date when standard time is in effect, and if
you set isdst to a positive value, or if the date is one where
daylight time is in effect and you set isdst to 0, then the time will
be adjusted by an hour (forward or back, respectively).  If isdst and
the daylight status of the date agree, thn no conversion is done.

Thus in the code below, since July 1 is a DST date and I set isdst to 0,
the time was interpreted as standard time and was adjusted forward.

Thanks to Robert * and Mahendra Ramachandran.  Neither of them
actually provided the solution, but things they suggested helped clue
me in.

Quote:>    #include <time.h>
>    #include <stdio.h>
>    int main(void)
>    {
>      struct tm t = { 0,    /* seconds */
>                     30,    /* minutes */
>                      8,    /* hours since midnight */
>                      1,    /* day of month */
>                      6,    /* months since January */
>                     98,    /* years since 1900 */
>                      0,    /* day of week (reset by mktime) */
>                      0,    /* day of year (reset by mktime) */
>                      0};   /* daylight/standard switch */
>                            /* --changing has no effect */

                                   ^^^^^^^^^^^^^^^^^^^^^^^^Wrong...

Quote:>      time_t    c;
>      c = mktime(&t);
>      printf("%s\n", ctime(&c));
>      return 0;
>    }

--
                Matthew Saltzman
                Clemson University Math Sciences


 
 
 

1. Question: find -f . -ctime +2 -type f

Re: Question: find -f . -ctime +2 -type f

is   -f .    the default? (Is it neccessary to specify each time ? )

I'm looking for files from the last two days, but seem to be getting
everything in all my directories.
Suggestions welcome.
TIA -R

2. ORACLE V7.0.16 on RAID 5 disks

3. OSX/SunOS ctime() type questions

4. LSM changes for 2.5.38

5. ctime(), ctime_r() question

6. Sun Sparc faster then intel pentium: is this true????

7. Unix programming question - Strange time/ctime thing.

8. PPPD Woes, help requested

9. mktime() and 'tm' structure

10. mktime alternative that creates a GMT 'struct tm' ???

11. Bug (I think) in 'mktime' library function

12. Y2K compliance of mktime

13. mktime & TimeZones