This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
mktime DST detection and time field normalisation.
- From: Toby Collett <thjc at plan9 dot net dot nz>
- To: libc-help at sourceware dot org
- Date: Sat, 23 Oct 2010 14:39:03 +0200
- Subject: mktime DST detection and time field normalisation.
Hi all,
I have a query about the behaviour of mktime. It seems that if you are
relying on both DST detection and time field normalisation you can get
incorrect timezone results. It seems that the DST detection is done
before the field normalisation. For example the following code:
#include <stdio.h>
#include <time.h>
void main(void)
{
setenv("TZ","GMT0BST,M3.5.0/1,M10.5.0/2",1);
tzset();
struct tm tm1,tm2,tm3,tm4;
tm1.tm_sec=1;
tm1.tm_min=0;
tm1.tm_hour=1;
tm1.tm_mday=31;
tm1.tm_mon=9;
tm1.tm_year=110;
tm1.tm_isdst=-1;
tm2=tm1;
tm2.tm_hour=0;
tm2.tm_min=59;
tm2.tm_sec=61;
tm3=tm1;
tm3.tm_mday=10;
tm4=tm2;
tm4.tm_mday=10;
if (mktime(&tm1) != mktime(&tm2))
printf("Times tm1 and tm2 differ\n");
if (mktime(&tm3) != mktime(&tm4))
printf("Times tm3 and tm4 differ\n");
}
results in 'Timers tm1 and tm2 differ', whereas I would have expected
them to match. I had a quick look at the mktime code, and as expected
it was very complicated. Also had no luck searching the mailing
lists/bug databases for anything relevant, possibly due to the level
of noise on other timezone/dst questions.
Is this a known limitation of the mktime dst detection algorithm?
I am using the ubuntu lucid libc 2.11.1-0ubuntu7 (same result on
2.12.1-0ubuntu8) I can also try against git if desired.
Regards,
Toby Collett