Thierry-Michel Barral wrote:
> If I give a date like '11:54:00 30/01/2001', and ask for %H:%M, hour and =
> minutes, everything's fine.
> But if I use '11:54:00 30/09/2001' as date, I will get 12:54, not 11:54.
> This is understandable, cause of the saving daylight.
> 
> But here, the time I give to the plugin if the real time I want to see =
> formated !


Matthew Tuck wrote:
> The test that failed for me was:
> 
> -- test --
> [% USE date %]
> [% date.format('4:20:00 6-13-2000', '%H') %]
> 
> -- expect --
> 04
> 
> On my system, this came back with "05".

[...]

> Because @date originally only has 6 members, the extra 3 get filled in
> with 0.  So having read the mktime man page, I added another statement
> right after the @date assignment:
> 
>       @date = (@date, 0, 0, -1);
> 
> This made it work.

I think the problem was that I had an extra localtime() in there
just after that block.  If the time was read from the system (e.g. 
now) then it needs to be localtime()'d to account for DST but if
supplied as a time/date string then it shouldn't.

So the following patch fixes it to how I *think* it should work.
Does this then work as expected for everyone?

A


--- Date.pm     2001/09/06 14:00:33     2.22
+++ Date.pm     2001/09/06 19:20:16     2.24
@@ -18,7 +18,7 @@
 #
 #----------------------------------------------------------------------------
 #
-# $Id: Date.pm,v 2.22 2001/09/06 14:00:33 abw Exp $
+# $Id: Date.pm,v 2.24 2001/09/06 19:20:16 abw Exp $
 #
 #============================================================================
 
@@ -31,7 +31,7 @@
 
 use POSIX ();
 
-$VERSION = sprintf("%d.%02d", q$Revision: 2.22 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 2.24 $ =~ /(\d+)\.(\d+)/);
 $FORMAT  = '%H:%M:%S %d-%b-%Y';    # default strftime() format
 
 
@@ -84,7 +84,11 @@
                    : ($params->{ locale } || $self->{ locale });
     my (@date, $datestr);
 
-    unless ($time =~ /^\d+$/) {
+    if ($time =~ /^\d+$/) {
+       # $time is now in seconds since epoch
+       @date = (localtime($time))[0..6];
+    }
+    else {
        # if $time is numeric, then we assume it's seconds since the epoch
        # otherwise, we try to parse it as a 'H:M:S D:M:Y' string
        @date = (split(/(?:\/| |:|-)/, $time))[2,1,0,3..5];
@@ -96,8 +100,6 @@
        $time = &POSIX::mktime(@date);
     }
     
-    # $time is now in seconds since epoch
-    @date = (localtime($time))[0..6];
 
     if ($locale) {
        # format the date in a specific locale, saving and subsequently
@@ -280,7 +282,7 @@
 
 =head1 VERSION
 
-2.21, distributed as part of the
+2.22, distributed as part of the
 Template Toolkit version 2.04e, released on 06 September 2001.
 
 


Reply via email to