7 use Date::Calc qw(Parse_Date Decode_Date_EU Decode_Date_US Time_to_Date check_date);
11 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
26 #Get the database handle
27 my $dbh = C4::Context->dbh;
28 return C4::Context->preference('dateformat');
31 sub display_date_format
33 my $dateformat = get_date_format();
35 if ( $dateformat eq "us" )
39 elsif ( $dateformat eq "metric" )
43 elsif ( $dateformat eq "iso" )
49 return "Invalid date format: $dateformat. Please change in system preferences";
65 # $olddate=~s#/|\.|-##g;
66 my ($year,$month,$day)=Parse_Date($olddate);
67 ($year,$month,$day)=split /-|\/|\.|:/,$olddate unless ($year && $month);
68 # warn "$olddate annee $year mois $month jour $day";
69 if ($year>0 && $month>0){
70 my $dateformat = get_date_format();
71 $dateformat="metric" if (index(":",$olddate)>0);
72 if ( $dateformat eq "us" )
74 $newdate = sprintf("%02d/%02d/%04d",$month,$day,$year);
76 elsif ( $dateformat eq "metric" )
78 $newdate = sprintf("%02d/%02d/%04d",$day,$month,$year);
80 elsif ( $dateformat eq "iso" )
82 # Date_Init("DateFormat=iso");
83 $newdate = sprintf("%04d-%02d-%02d",$year,$month,$day);
87 return "Invalid date format: $dateformat. Please change in system preferences";
89 # warn "newdate :$newdate";
94 sub format_date_in_iso
103 if (check_whether_iso($olddate)){
106 my $dateformat = get_date_format();
107 my ($year,$month,$day);
109 my $tmpolddate=$olddate;
110 $tmpolddate=~s#/|\.|-|\\##g;
111 $dateformat="metric" if (index(":",$olddate)>0);
112 if ( $dateformat eq "us" )
114 ($month,$day,$year)=split /-|\/|\.|:/,$olddate unless ($year && $month);
115 if ($month>0 && $day >0){
116 @date = Decode_Date_US($tmpolddate);
118 @date=($year, $month,$day)
121 elsif ( $dateformat eq "metric" )
123 ($day,$month,$year)=split /-|\/|\.|:/,$olddate unless ($year && $month);
124 if ($month>0 && $day >0){
125 @date = Decode_Date_EU($tmpolddate);
127 @date=($year, $month,$day)
130 elsif ( $dateformat eq "iso" )
132 ($year,$month,$day)=split /-|\/|\.|:/,$olddate unless ($year && $month);
133 if ($month>0 && $day >0){
134 @date=($year, $month,$day) if (check_date($year,$month,$day));
136 @date=($year, $month,$day)
143 $newdate = sprintf("%04d-%02d-%02d",$date[0],$date[1],$date[2]);
148 sub check_whether_iso
151 my @olddate= split /\-/,$olddate ;
152 return 1 if (length($olddate[0])==4 && length($olddate[1])<=2 && length($olddate[2])<=2);