Koha/C4/Date.pm
tipaul 97182dceb2 improvements from SAN Ouest Provence :
* introducing a category_type into categories. It can be A (adult), C (children), P (Professionnal), I (institution/organisation).
* each category_type has it's own forms to create members.
* the borrowers table has been heavily modified (many fields changed), to get something more logic & readable
* reintroducing guarantor/guanrantee system that is now independant from hardcoded C/A for categories
* updating templates to fit template rules

(see mail feb, 17 on koha-devel "new features for borrowers" for more details)
2006-04-14 09:31:24 +00:00

165 lines
3 KiB
Perl

#!/usr/bin/perl -w
package C4::Date;
use strict;
use C4::Context;
use Date::Manip;
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 0.01;
@ISA = qw(Exporter);
@EXPORT = qw(
&display_date_format
&format_date
&format_date_in_iso
&today
get_date_format_string_for_DHTMLcalendar
);
sub get_date_format
{
#Get the database handle
my $dbh = C4::Context->dbh;
return C4::Context->preference('dateformat');
}
sub display_date_format
{
my $dateformat = get_date_format();
if ( $dateformat eq "us" )
{
return "mm/dd/yyyy";
}
elsif ( $dateformat eq "metric" )
{
return "dd/mm/yyyy";
}
elsif ( $dateformat eq "iso" )
{
return "yyyy-mm-dd";
}
else
{
return "Invalid date format: $dateformat. Please change in system preferences";
}
}
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
{
my $olddate = shift;
my $newdate;
if ( ! $olddate )
{
return "";
}
my $dateformat = get_date_format();
if ( $dateformat eq "us" )
{
Date_Init("DateFormat=US");
$olddate = ParseDate($olddate);
$newdate = UnixDate($olddate,'%m/%d/%Y');
}
elsif ( $dateformat eq "metric" )
{
Date_Init("DateFormat=metric");
$olddate = ParseDate($olddate);
$newdate = UnixDate($olddate,'%d/%m/%Y');
}
elsif ( $dateformat eq "iso" )
{
Date_Init("DateFormat=iso");
$olddate = ParseDate($olddate);
$newdate = UnixDate($olddate,'%Y-%m-%d');
}
else
{
return "Invalid date format: $dateformat. Please change in system preferences";
}
}
sub format_date_in_iso
{
my $olddate = shift;
my $newdate;
if ( ! $olddate )
{
return "";
}
my $dateformat = get_date_format();
if ( $dateformat eq "us" )
{
Date_Init("DateFormat=US");
$olddate = ParseDate($olddate);
}
elsif ( $dateformat eq "metric" )
{
Date_Init("DateFormat=metric");
$olddate = ParseDate($olddate);
}
elsif ( $dateformat eq "iso" )
{
Date_Init("DateFormat=iso");
$olddate = ParseDate($olddate);
}
else
{
return "9999-99-99";
}
$newdate = UnixDate($olddate, '%Y-%m-%d');
return $newdate;
}
#function to return a current date OUEST-PROVENCE
sub today
{
my ($adddate) =@_;
my($j,$m,$a)=(localtime)[3,4,5];
if ($j<10) {
$j= '0'.$j;
}
$m=$m+1;
if ($m<10){
$m= '0'.$m
}
$a=$a+1900+$adddate;
return format_date("$a-$m-$j");
}
1;