develooper Front page | perl.perl5.porters | Postings from January 2003

[PATCH] Re: [perl #19393] Bug in Time::localtime?

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
January 1, 2003 13:46
Subject:
[PATCH] Re: [perl #19393] Bug in Time::localtime?
Message ID:
20030101214324.F12907@fdgroup.com
On Mon, Dec 30, 2002 at 09:58:51PM +0000, Ton Hospel wrote:
> In article <20021227215004.A28503@_dgroup.com>,
> 	Dave Mitchell <davem@fdgroup.com> writes:
> > It's just the transition to DST - there are two hours that map to the same
> > internal time, so Not-A-Bug.
> > ie at 00:00, the clocks go back to 23:00.
> > 
> Well, not exactly:

[ snip]

> So time actually skips 0:00 to 1:00, and there is no 0:00 really.
> Still, if you want to put it anywhere, it corresponds to
> 1034478000+3600=1034481600
> 
> So I'd call this a bug:
> TZ=Chile/Continental perl -MTime::Local -wle 'print timelocal(0,0,0,13,9,2002)'
> 1034478000
> TZ=Chile/Continental perl -MTime::Local -wle 'print timelocal(0,0,0,13,9,102)'
> 1034478000
> 
> It should be either an error or 1034481600

D'oh - I got confused by Chile's clocks going fowards in the autumn,
whereas they go backwards in the UK and other places at that time :-(

So yes, its a bug.
Attached patch adjusts 'inbetween' dates to the DST-shifted equivalent.

-- 
"You're so sadly neglected, and often ignored.
A poor second to Belgium, When going abroad."
Monty Python - "Finland"


--- lib/Time/Local.pm-	Wed Jan  1 21:24:34 2003
+++ lib/Time/Local.pm	Wed Jan  1 22:29:54 2003
@@ -132,7 +132,18 @@
 	or return $loc_t;
 
     # Adjust for DST change
-    $loc_t + $dst_off;
+    $loc_t += $dst_off;
+
+    # for a negative offset from GMT, and if the original date
+    # was a non-extent gap in a forward DST jump, we should
+    # now have the wrong answer - undo the DST adjust;
+
+    return $loc_t if $zone_off <= 0;
+
+    my ($s,$m,$h) = localtime($loc_t);
+    $loc_t -= $dst_off if $s != $_[0] || $m != $_[1] || $h != $_[2];
+
+    $loc_t;
 }
 
 
--- lib/Time/Local.t-	Wed Jan  1 21:24:45 2003
+++ lib/Time/Local.t	Wed Jan  1 22:47:17 2003
@@ -28,7 +28,7 @@
 # use vmsish 'time' makes for oddness around the Unix epoch
 if ($^O eq 'VMS') { $time[0][2]++ }
 
-print "1..", @time * 2 + 5, "\n";
+print "1..", @time * 2 + 6, "\n";
 
 $count = 1;
 for (@time) {
@@ -93,6 +93,20 @@
   or print "not ";
 print "ok ", $count++, "\n";
 
+# bugid #19393
+# At a DST transition, the clock skips forward, eg from 01:59:59 to
+# 03:00:00. In this case, 02:00:00 is an invalid time, and should be
+# treated like 03:00:00 rather than 01:00:00 - negative zone offsets used
+# to do the latter
+
+{
+    my $hour = (localtime(timelocal(0, 0, 2, 7, 3, 102)))[2];
+    # testers in US/Pacific should get 3,
+    # other testers should get 2
+    print "not " unless $hour == 2 || $hour == 3;
+    print "ok ", $main::count++, "\n";
+}
+
 
 #print "Testing timelocal.pl module too...\n";
 package test;

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About