This is the mail archive of the
libc-hacker@cygnus.com
mailing list for the glibc project.
ctime problem (PR 939)
- To: libc-hacker@cygnus.com
- Subject: ctime problem (PR 939)
- From: Andreas Jaeger <aj@arthur.rhein-neckar.de>
- Date: 01 Feb 1999 16:55:41 +0100
- Cc: Mike.Jones@ons.gov.uk
- Mail-Copies-To: never
Hi,
Mike send us a bug report where he reported what looks like a strange
bug. For full details of the discussion so far, please read PR
libc/939.
Calling the appended program with TZ set for Great Britain, ctime(0)
report 1 o'clock - but strftime report the right time:
$ TZ=Europe/London ./ctimetry
time_t 0 converts to Thu Jan 1 01:00:00 1970
Time zones are GMT and BST
00:00:00 1970/01/01
Daylight saving is off
strftime reports: Thu, 01 Jan 1970 00:00:00 +0000 GMT
Mike reported this for 2.0.7 but I can reproduce this with 2.0.112.
If using localtime instead of gmtime the output is:
$ TZ=Europe/London ./ctimetry
time_t 0 converts to Thu Jan 1 01:00:00 1970
Time zones are GMT and BST
01:00:00 1970/01/01
Daylight saving is off
strftime reports: Thu, 01 Jan 1970 01:00:00 +0100 BST
Note especially the BST.
I'm puzzled at the moment. Could anybody please look into this and
tell me what's wrong?
Thanks,
Andreas
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
main (int argc, char **argv)
{
time_t x;
struct tm *t;
char s[1000];
x = 0l;
printf ("time_t %ld converts to %s", x, ctime (&x));
printf ("Time zones are %s and %s\n", tzname[0], tzname[1]);
#if 1
t = gmtime (&x);
#else
t = localtime (&x);
#endif
printf ("%02d:%02d:%02d ", t->tm_hour, t->tm_min, t->tm_sec);
printf ("%04d/%02d/%02d\n",
(t->tm_year + 1900), (t->tm_mon + 1), t->tm_mday);
printf ("Daylight saving is %s\n", t->tm_isdst ? "on" : "off");
strftime (s, sizeof(s), "%a, %d %b %Y %T %z %Z", t);
printf ("strftime reports: %s\n", s);
}
--
Andreas Jaeger aj@arthur.rhein-neckar.de jaeger@informatik.uni-kl.de
for pgp-key finger ajaeger@aixd1.rhrk.uni-kl.de