gmtime()

Markus Wichmann <[email protected]> Mon, 05 Dec 2011 15:00:08 +0100
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
Hi all,

after we had a wonderful discussion of localtime(), I discovered a bug
in gmtime(), namely it doesn't set the timezone.

OK, could also be that it is strftime() that is broken. Here's my test
program:

#include <time.h>
#include <sys/time.h>
#include <locale.h>
#include <stdio.h>

int main()
{
    struct timeval tv;
    char buf[512];

    setlocale(LC_ALL, "");

    gettimeofday(&tv, 0);
    strftime(buf, sizeof buf, "The current time in GMT is: %c",
gmtime(&tv.tv_sec));
    puts(buf);
    strftime(buf, sizeof buf, "The current local time is: %c",
localtime(&tv.tv_sec));
    puts(buf);
    return 0;
}

Compiled with glibc this yields:
The current time in GMT is: Mo 05 Dez 2011 13:48:35 GMT
The current local time is: Mo 05 Dez 2011 14:48:35 CET

Compiled with dietlibc:
The current time in GMT is: Dec Mon 05 13:48:54 CET 2011
The current local time is: Dec Mon 05 14:48:54 CET 2011

As you can see, the timezone output of gmtime() is clearly broken,
because that time is in GMT. So... either we need a timezone field in
struct tm, or we need strftime() to shut up about timezones. Which one
will it be?

And, by the way, I didn't notice the bug mentioned earlier. I guess leap
seconds are taken care of by NTP.

CYA,
Markus
-- 
() ASCII Ribbon Campaign
/\ Against HTML in Mail and News