-#!/usr/bin/perl -w
-
package C4::Date;
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
use strict;
use C4::Context;
@EXPORT = qw(
&display_date_format
+ &get_date_format_string_for_DHTMLcalendar
&format_date
&format_date_in_iso
+ &fixdate
);
}
}
+sub get_date_format_string_for_DHTMLcalendar {
+ my $dateformat = get_date_format();
+
+ if ( $dateformat eq 'us' ) {
+ return '%m/%d/%Y';
+ }
+ elsif ( $dateformat eq 'metric' ) {
+ return '%d/%m/%Y';
+ }
+ elsif ( $dateformat eq "iso" ) {
+ return '%Y-%m-%d';
+ }
+ else {
+ return 'Invalid date format: '
+ . $dateformat . '.'
+ . ' Please change in system preferences';
+ }
+}
sub format_date
{
return 1 if (length($olddate[0])==4 && length($olddate[1])<=2 && length($olddate[2])<=2);
return 0;
}
+
+=head2 fixdate
+
+( $date, $invalidduedate ) = fixdate( $year, $month, $day );
+
+=cut
+
+sub fixdate {
+ my ( $year, $month, $day ) = @_;
+ my $invalidduedate;
+ my $date;
+ if ( $year && $month && $day ) {
+ if ( ( $year eq 0 ) && ( $month eq 0 ) && ( $year eq 0 ) ) {
+ }
+ else {
+ if ( ( $year eq 0 ) || ( $month eq 0 ) || ( $year eq 0 ) ) {
+ $invalidduedate = 1;
+ }
+ else {
+ if (
+ ( $day > 30 )
+ && ( ( $month == 4 )
+ || ( $month == 6 )
+ || ( $month == 9 )
+ || ( $month == 11 ) )
+ )
+ {
+ $invalidduedate = 1;
+ }
+ elsif ( ( $day > 29 ) && ( $month == 2 ) ) {
+ $invalidduedate = 1;
+ }
+ elsif (
+ ( $month == 2 )
+ && ( $day > 28 )
+ && ( ( $year % 4 )
+ && ( ( !( $year % 100 ) || ( $year % 400 ) ) ) )
+ )
+ {
+ $invalidduedate = 1;
+ }
+ else {
+ $date = "$year-$month-$day";
+ }
+ }
+ }
+ }
+ return ( $date, $invalidduedate );
+}
+
1;