Change 18267 by [EMAIL PROTECTED] on 2002/12/09 00:10:09
Subject: Re: [perl #18238] timezone and gmt offset as output by
POSIX::strftime() are sometimes wrong
From: Slaven Rezic <[EMAIL PROTECTED]>
Date: 09 Nov 2002 23:21:16 +0100
Message-ID: <[EMAIL PROTECTED]>
Affected files ...
.... //depot/perl/config_h.SH#265 edit
.... //depot/perl/ext/POSIX/t/posix.t#15 edit
.... //depot/perl/util.c#373 edit
Differences ...
==== //depot/perl/config_h.SH#265 (text) ====
Index: perl/config_h.SH
--- perl/config_h.SH#264~18030~ Sat Oct 19 07:10:21 2002
+++ perl/config_h.SH Sun Dec 8 16:10:09 2002
@@ -2994,10 +2994,15 @@
* This symbol, if defined, indicates to the C program that
* the struct tm has a tm_zone field.
*/
+/* HAS_TM_TM_GMTOFF:
+ * This symbol, if defined, indicates to the C program that
+ * the struct tm has a tm_gmtoff field.
+ */
#$i_time I_TIME /**/
#$i_systime I_SYS_TIME /**/
#$i_systimek I_SYS_TIME_KERNEL /**/
#$d_tm_tm_zone HAS_TM_TM_ZONE /**/
+#$d_tm_tm_gmtoff HAS_TM_TM_GMTOFF /**/
/* I_USTAT:
* This symbol, if defined, indicates that <ustat.h> exists and
==== //depot/perl/ext/POSIX/t/posix.t#15 (text) ====
Index: perl/ext/POSIX/t/posix.t
--- perl/ext/POSIX/t/posix.t#14~17822~ Mon Sep 2 12:29:52 2002
+++ perl/ext/POSIX/t/posix.t Sun Dec 8 16:10:09 2002
@@ -11,7 +11,7 @@
}
require "./test.pl";
-plan(tests => 61);
+plan(tests => 66);
use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write
@@ -182,6 +182,26 @@
try_strftime("Wed Mar 01 00:00:00 2000 061", 0,0,0, 1,2,100);
try_strftime("Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100);
&POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale};
+
+SKIP: {
+ # XXX wait for smokers to see which OSs else to skip
+ skip("No mktime and/or tm_gmtoff", 5)
+ if !$Config{d_mktime} || !$Config{d_tm_tm_gmtoff} || !$Config{d_tm_tm_zone};
+ local $ENV{TZ} = "Europe/Berlin";
+
+ # May fail for ancient FreeBSD versions.
+ # %z is not included in POSIX, but valid on Linux and FreeBSD.
+ foreach $def ([1000,'Sun Sep 9 03:46:40 2001 +0200 CEST'],
+ [900, 'Thu Jul 9 18:00:00 1998 +0200 CEST'],
+ [800, 'Tue May 9 08:13:20 1995 +0200 CEST'],
+ [700, 'Sat Mar 7 21:26:40 1992 +0100 CET'],
+ [600, 'Thu Jan 5 11:40:00 1989 +0100 CET'],
+ ) {
+ my($t, $expected) = @$def;
+ my @tm = localtime($t*1000000);
+ is(strftime("%c %z %Z",@tm), $expected, "validating zone setting: $expected");
+ }
+}
{
for my $test (0, 1) {
==== //depot/perl/util.c#373 (text) ====
Index: perl/util.c
--- perl/util.c#372~18225~ Sun Dec 1 19:09:42 2002
+++ perl/util.c Sun Dec 8 16:10:09 2002
@@ -3388,6 +3388,20 @@
mytm.tm_yday = yday;
mytm.tm_isdst = isdst;
mini_mktime(&mytm);
+ /* use libc to get the values for tm_gmtoff and tm_zone [perl #18238] */
+#if defined(HAS_MKTIME) && (defined(HAS_TM_TM_GMTOFF) || defined(HAS_TM_TM_ZONE))
+ STMT_START {
+ struct tm mytm2;
+ mytm2 = mytm;
+ mktime(&mytm2);
+#ifdef HAS_TM_TM_GMTOFF
+ mytm.tm_gmtoff = mytm2.tm_gmtoff;
+#endif
+#ifdef HAS_TM_TM_ZONE
+ mytm.tm_zone = mytm2.tm_zone;
+#endif
+ } STMT_END;
+#endif
buflen = 64;
New(0, buf, buflen, char);
len = strftime(buf, buflen, fmt, &mytm);
End of Patch.