[Koha] Patch to Members.pm to fix Joing/Expiry Date errors

Andrew Yager andrew at rwts.com.au
Sat Jul 21 17:45:41 NZST 2007


Hi,

I've just patched Date.pm and Members.pm to fix Joining/Expiry date  
problems against 2.2.9.

These changes mean that Members.pm no longer needs to make use of  
Date::Manip functions during member creation.

These patches may help someone else running the current release  
version. It seems it has been fixed in cvs head.

Thanks,
Andrew

---------

diff -u ./Date.pm /usr/local/koha/intranet/modules/C4/Date.pm
--- ./Date.pm   2007-04-26 20:03:54.000000000 +1000
+++ /usr/local/koha/intranet/modules/C4/Date.pm 2007-07-21  
15:34:23.000000000 +1000
@@ -4,13 +4,13 @@

  use strict;
  use C4::Context;
-use Date::Calc qw(Parse_Date Decode_Date_EU Decode_Date_US  
Time_to_Date check_date);
+use Date::Calc qw(Parse_Date Decode_Date_EU Decode_Date_US  
Time_to_Date check_date Today Add_Delta_YM);

  require Exporter;

  use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

-$VERSION = 0.01;
+$VERSION = 0.01;

  @ISA = qw(Exporter);

@@ -18,6 +18,8 @@
               &display_date_format
               &format_date
               &format_date_in_iso
+             &add_years
+             &today
  );


@@ -50,6 +52,63 @@
         }
  }

+sub add_years
+{
+       my $olddate = shift;
+       my $delta = shift;
+       my $newdate;
+       $olddate = format_date_in_iso($olddate);
+       my ($year,$month,$day)=split (/-|\/|\.|:/,$olddate);
+       ($year,$month,$day)=Add_Delta_YM($year, $month, $day, $delta,  
0);
+
+       my $dateformat = get_date_format();
+    $dateformat="metric" if (index(":",$olddate)>0);
+    if ( $dateformat eq "us" )
+    {
+        $newdate = sprintf("%02d/%02d/%04d",$month,$day,$year);
+    }
+    elsif ( $dateformat eq "metric" )
+    {
+        $newdate = sprintf("%02d/%02d/%04d",$day,$month,$year);
+    }
+    elsif ( $dateformat eq "iso" )
+    {
+#              Date_Init("DateFormat=iso");
+        $newdate = sprintf("%04d-%02d-%02d",$year,$month,$day);
+    }
+    else
+    {
+        return "Invalid date format: $dateformat. Please change in  
system preferences";
+    }
+       return $newdate;
+}
+
+sub today
+{
+       my ($year, $month, $day) = Today();
+       my $newdate;
+
+       my $dateformat = get_date_format();
+    if ( $dateformat eq "us" )
+    {
+        $newdate = sprintf("%02d/%02d/%04d",$month,$day,$year);
+    }
+    elsif ( $dateformat eq "metric" )
+    {
+        $newdate = sprintf("%02d/%02d/%04d",$day,$month,$year);
+    }
+    elsif ( $dateformat eq "iso" )
+    {
+#              Date_Init("DateFormat=iso");
+        $newdate = sprintf("%04d-%02d-%02d",$year,$month,$day);
+    }
+    else
+    {
+        return "Invalid date format: $dateformat. Please change in  
system preferences";
+    }
+       return $newdate;
+}
+

  sub format_date
  {

diff -u ./Members.pm /usr/local/koha/intranet/modules/C4/Members.pm
--- ./Members.pm        2007-04-06 19:22:07.000000000 +1000
+++ /usr/local/koha/intranet/modules/C4/Members.pm      2007-07-21  
15:25:19.000000000 +1000
@@ -129,7 +129,7 @@
         my (%data) = @_;
         my $dbh = C4::Context->dbh;
         $data{'dateofbirth'}=format_date_in_iso($data{'dateofbirth'});
-       $data{'joining'} = &ParseDate("today") unless $data{'joining'};
+       $data{'joining'} = &today() unless $data{'joining'};
         $data{'joining'}=format_date_in_iso($data{'joining'});
         # if expirydate is not set, calculate it from borrower  
category subscription duration
         unless ($data{'expiry'}) {
@@ -137,7 +137,7 @@
                 $sth->execute($data{'categorycode'});
                 my ($enrolmentperiod) = $sth->fetchrow;
                 $enrolmentperiod = 12 unless ($enrolmentperiod);
-               $data{'expiry'} = &DateCalc($data 
{'joining'},"$enrolmentperiod years");
+               $data{'expiry'} = &add_years($data{'joining'}, 
$enrolmentperiod);
         }
         $data{'expiry'}=format_date_in_iso($data{'expiry'});
  #      $data{'borrowernumber'}=NewBorrowerNumber();

_________________________
Andrew Yager, Managing Director
Real World Technology Solutions Pty Ltd
ph: 1300 798 718 or (02) 9563 4840
fax: (02) 9563 4848 mob: 0405 152 568
http://www.rwts.com.au/
_________________________

Real World Technology Solutions is an Authorised Apple Reseller,  
Telstra Dealer, Microsoft Small Business Solutions Specialist and  
Cisco Registered Partner.



More information about the Koha mailing list