[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#634007: libc6: strftime %s wrong result when struct tm is from gmtime_r() and timezone is non UTC



Package: libc6
Version: 2.11.2-10

Hi,

When use time from gmtime_r() and strftime() in local (non UTC) timezone strftime
is able to recognize timezone (UTC) of time in tm, but %s ("the number of seconds
since the Epoch") is wrong (as though tm was in the local timezone).

Best regards,
Robert Paciorek
http://www.opcode.eu.org/bercik


-- Step to reproduce:

following code:

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

main() {
	time_t t = 0;
	struct tm tt;
	char buf[40];

	puts("using strftime and %s from gmtime_r time in non UTC timezone");
	setenv("TZ", "CET");
	gmtime_r(&t, &tt);
	strftime(buf, 35, "\t%s TZ: %z %Z", &tt);
	puts(buf);
	puts("the number of seconds since the Epoch is wrong. Should be 0.");
	puts("strftime knows that tt is in UTC (GMT), " \
		"but %s interprets in enviroment TZ (CET)\n");

	puts("using strftime and %s from gmtime_r time in UTC timezone");
	setenv("TZ", "UTC");
	strftime(buf, 35, "\t%s TZ: %z %Z", &tt);
	puts(buf);
	puts("the number of seconds since the Epoch is correct.");
}

produces outputs:

using strftime and %s from gmtime_r time in non UTC timezone
	-3600 TZ: +0000 GMT
the number of seconds since the Epoch is wrong. Should be 0.
strftime knows that tt is in UTC (GMT), but %s interprets in enviroment TZ (CET)

using strftime and %s from gmtime_r time in UTC timezone
	0 TZ: +0000 GMT
the number of seconds since the Epoch is correct.


-- System Information:
Debian Release: 6.0.1
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/32 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8
Shell: /bin/sh linked to /bin/dash

Versions of packages libc6 depends on:
ii  libc-bin                      2.11.2-10  Embedded GNU C Library: Binaries
ii  libgcc1                       1:4.4.5-8  GCC support library

libc6 recommends no packages.

Versions of packages libc6 suggests:
ii  debconf [debconf-2.0]         1.5.36.1   Debian configuration management sy
pn  glibc-doc                     <none>     (no description available)
ii  locales                       2.11.2-10  Embedded GNU C Library: National L

-- debconf information:
  glibc/upgrade: true
  glibc/restart-services:
  glibc/disable-screensaver:
  glibc/restart-failed:



Reply to: