You are here: Foswiki>Tasks Web>Item11308 (05 Jul 2015, GeorgeClark)Edit Attach

Item11308: Foswiki time functions can't parse dates earlier than 1970.

pencil
Priority: Normal
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component: FoswikiTime
Branches: Release01x01 trunk
Reported By: MichaelDaum
Waiting For:
Last Change By: GeorgeClark
Time::Local does just fine without the 1900 tricks in Foswiki::Time ... as far as I can see. Got things working for me wink using this patch

--- lib/Foswiki/Time.pm (revision 13236)
+++ lib/Foswiki/Time.pm (working copy)
@@ -131,7 +131,7 @@
     #TODO: allow /.: too
     if ( $date =~ /(\d+)[-\s]+([a-z]{3})[-\s]+(\d+)(?:[-\s]+(\d+):(\d+))?/i ) {
         my $year = $3;
-        $year -= 1900 if ( $year > 1900 );
+        #$year -= 1900 if ( $year > 1900 );
 
         my $mon = $MON2NUM{ lc($2) };
         return undef unless defined $mon;
@@ -153,7 +153,7 @@
         my ( $Y, $M, $D, $h, $m, $s, $tz ) =
           ( $1, $2 || 1, $3 || 1, $4 || 0, $5 || 0, $6 || 0, $7 || '' );
         $M--;
-        $Y -= 1900 if ( $Y > 1900 );
+        #$Y -= 1900 if ( $Y > 1900 );
         if ($tz) {
             my $tzadj = 0;
             if ( $tz eq 'Z' ) {
@@ -200,7 +200,7 @@
     #$month_p = $MON2NUM{ lc($month_p) } if (defined($MON2NUM{ lc($month_p) }));
 
         #TODO: unhappily, this means 09 == 1909 not 2009
-        $year -= 1900 if ( $year > 1900 );
+        #$year -= 1900 if ( $year > 1900 );
 
         #range checks
         return undef if ( defined($M) && ( $M < 1 || $M > 12 ) );

-- MichaelDaum - 28 Nov 2011

I believe this can go a bit further. The recent versions of Time::Local have full support for negative and positive epoch values.
From Time::Local documentation: "On perl version 5.12.0 and newer, negative epoch values are fully supported.

On older versions of perl, negative epoch (time_t) values, which are not officially supported by the POSIX standards, are known not to work on some systems. These include MacOS (pre-OSX) and Win32.

On systems which do support negative epoch values, this module should be able to cope with dates before the start of the epoch, down the minimum value of time_t for the system.

I added some unit test values for early 1900, 1800s, 1700s, as well as 2-digit and 3-digit years. They seem to work fine with the above change, provided that we also switch to use the localtime_nocheck and gmtime_nocheck routines. Dates earlier than 1900 are rejected unless the nocheck version of the routines are used.

Not sure if these changes would need a feature proposal or not. But in any event, I suspect they are too risky for 1.1.5. Babar recently added all the time tests. Any comments?

-- GeorgeClark - 10 Mar 2012

If it doesn't break the unit tests I made, then go for it smile

-- OlivierRaginel - 10 Mar 2012

Re-opening this one.

Using nocheck is not a good idea. Invalid dates can slip through, and it can return bad results when perl doesn't support negative epochs.
  • Restore use of date checking when calling localtime
  • Separate out pre-1970 tests into separate tests.
  • Update unit tests to detect when perl doesn't support negative epochs, and skip the pre-1970 tests. Also skip them for Foswiki < 1.2.
  • Add a checker to warn the admin if dates prior to 1970 are going to fail, recommend perl 5.12+ or 64 bit system.

Babar, any concerns?

-- GeorgeClark - 13 Mar 2013

Setting waiting for release. This has been stable for a while.

-- GeorgeClark - 02 Jun 2014
 
Topic revision: r12 - 05 Jul 2015, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy