rev 1876 - trunk/buscador/lib/Buscador

[prev] [thread] [next] [lurker] [Date index for 2005/02/14]

From: simon
Subject: rev 1876 - trunk/buscador/lib/Buscador
Date: 10:42 on 14 Feb 2005
Author: simon
Date: 2005-02-14 10:42:37 +0000 (Mon, 14 Feb 2005)
New Revision: 1876

Modified:
   trunk/buscador/lib/Buscador/Date.pm
Log:
Make fix_year safer. Memoize fix_year, fix_month.


Modified: trunk/buscador/lib/Buscador/Date.pm
===================================================================
--- trunk/buscador/lib/Buscador/Date.pm	2005-02-14 10:39:30 UTC (rev 1875)
+++ trunk/buscador/lib/Buscador/Date.pm	2005-02-14 10:42:37 UTC (rev 1876)
@@ -42,6 +42,7 @@
 use Time::Piece;
 use Time::Seconds;
 use Lingua::EN::Numbers::Ordinate;
+use Memoize;
 
 sub view :Exported {
     my $self = shift;
@@ -150,9 +151,11 @@
     return 1;
 }
 
+memoize('fix_year');
 sub fix_year {
     my $year = shift; return unless $year =~ /^\d+$/;
     $year   += 0; # force numerical    
+    return undef if $year < 1;
     my @lt   = localtime();
     my $cur  = sprintf("%02d", $lt[5] % 100) + 0;
     my $millenia = $lt[5] + 1900; $millenia -= $millenia % 1000;
@@ -162,7 +165,7 @@
     return $year;
 }
 
-
+memoize('fix_month');
 sub fix_month {
     my $month = shift;
     if ($month =~ /^\d+/) {

Generated at 09:00 on 19 Mar 2005 by mariachi 0.52