2 # This file is part of Koha.
4 # Koha is free software; you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation; either version 2 of the License, or (at your option) any later
9 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
15 # Suite 330, Boston, MA 02111-1307 USA
19 use Date::Calc qw(Parse_Date Decode_Date_EU Decode_Date_US Time_to_Date check_date);
23 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
31 &get_date_format_string_for_DHTMLcalendar
39 #Get the database handle
40 my $dbh = C4::Context->dbh;
41 return C4::Context->preference('dateformat');
44 sub display_date_format
46 my $dateformat = get_date_format();
48 if ( $dateformat eq "us" )
52 elsif ( $dateformat eq "metric" )
56 elsif ( $dateformat eq "iso" )
62 return "Invalid date format: $dateformat. Please change in system preferences";
66 sub get_date_format_string_for_DHTMLcalendar {
67 my $dateformat = get_date_format();
69 if ( $dateformat eq 'us' ) {
72 elsif ( $dateformat eq 'metric' ) {
75 elsif ( $dateformat eq "iso" ) {
79 return 'Invalid date format: '
81 . ' Please change in system preferences';
96 # $olddate=~s#/|\.|-##g;
97 my ($year,$month,$day)=Parse_Date($olddate);
98 ($year,$month,$day)=split /-|\/|\.|:/,$olddate unless ($year && $month);
99 # warn "$olddate annee $year mois $month jour $day";
100 if ($year>0 && $month>0){
101 my $dateformat = get_date_format();
102 $dateformat="metric" if (index(":",$olddate)>0);
103 if ( $dateformat eq "us" )
105 $newdate = sprintf("%02d/%02d/%04d",$month,$day,$year);
107 elsif ( $dateformat eq "metric" )
109 $newdate = sprintf("%02d/%02d/%04d",$day,$month,$year);
111 elsif ( $dateformat eq "iso" )
113 # Date_Init("DateFormat=iso");
114 $newdate = sprintf("%04d-%02d-%02d",$year,$month,$day);
118 return "Invalid date format: $dateformat. Please change in system preferences";
120 # warn "newdate :$newdate";
125 sub format_date_in_iso
134 if (check_whether_iso($olddate)){
137 my $dateformat = get_date_format();
138 my ($year,$month,$day);
140 my $tmpolddate=$olddate;
141 $tmpolddate=~s#/|\.|-|\\##g;
142 $dateformat="metric" if (index(":",$olddate)>0);
143 if ( $dateformat eq "us" )
145 ($month,$day,$year)=split /-|\/|\.|:/,$olddate unless ($year && $month);
146 if ($month>0 && $day >0){
147 @date = Decode_Date_US($tmpolddate);
149 @date=($year, $month,$day)
152 elsif ( $dateformat eq "metric" )
154 ($day,$month,$year)=split /-|\/|\.|:/,$olddate unless ($year && $month);
155 if ($month>0 && $day >0){
156 @date = Decode_Date_EU($tmpolddate);
158 @date=($year, $month,$day)
161 elsif ( $dateformat eq "iso" )
163 ($year,$month,$day)=split /-|\/|\.|:/,$olddate unless ($year && $month);
164 if ($month>0 && $day >0){
165 @date=($year, $month,$day) if (check_date($year,$month,$day));
167 @date=($year, $month,$day)
174 $newdate = sprintf("%04d-%02d-%02d",$date[0],$date[1],$date[2]);
179 sub check_whether_iso
182 my @olddate= split /\-/,$olddate ;
183 return 1 if (length($olddate[0])==4 && length($olddate[1])<=2 && length($olddate[2])<=2);