This is the mail archive of the
mailing list for the glibc project.
Different unixtimes, same localtime
- From: Dario Teixeira <dario dot teixeira at nleyten dot com>
- To: libc-help at sourceware dot org
- Date: Sat, 05 Nov 2016 13:16:12 +0000
- Subject: Different unixtimes, same localtime
- Authentication-results: sourceware.org; auth=none
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!
void print_tm (struct tm *tm)
printf ("\t%04d-%02d-%02d %02d:%02d:%02d, wday=%d, yday=%d,
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);
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);
printf ("ut1: %ld\n", ut1);