This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Different unixtimes, same localtime


Hi,

Either I've found a bug in localtime_r or I'm missing
something about its usage (probably the latter).
The problem is that I'm getting the exact same tm structure
for invocations of localtime_r with different Unix times.
Now, the times I'm using are special in that they represent
the same localtime in the provided locale.  Nevertheless,
the smaller one (212541000L) happened when DST was in effect,
whereas the second one (212544600L) happened one hour later
was DST was no longer in effect.  Shouldn't this difference
be signaled in the tm_isdst field?

The complete code that illustrates this problem is below.
Note that I'm setting TZ to the "Europe/Lisbon" timezone
and invoking tzset before localtime_r.

Thanks in advance for your time and assistance!
Best regards,
Dario Teixeira

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

void print_tm (struct tm *tm)
  {
printf ("\t%04d-%02d-%02d %02d:%02d:%02d, wday=%d, yday=%d, isdst=%d\n",
    1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday,
    tm->tm_hour, tm->tm_min, tm->tm_sec,
    tm->tm_wday, tm->tm_yday, tm->tm_isdst);
  }

void main ()
  {
  setenv ("TZ", ":Europe/Lisbon", 1);
  tzset ();

  time_t ut0 = 212541000L;
  time_t ut1 = 212544600L;
  struct tm tm0;
  struct tm tm1;
  localtime_r (&ut0, &tm0);
  localtime_r (&ut1, &tm1);

  printf ("ut0: %ld\n", ut0);
  print_tm (&tm0);
  printf ("ut1: %ld\n", ut1);
  print_tm (&tm1);
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]