]> git.koha-community.org Git - koha.git/blob - C4/Circulation/Date.pm
add security on borrowernumber,barcode for book issues
[koha.git] / C4 / Circulation / Date.pm
1 package C4::Circulation::Date;
2
3 # Copyright 2005 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 # $id:$
21
22 use strict;
23 use C4::Context;
24
25 require Exporter;
26
27 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
28
29 $VERSION = do { my @v = '$Revision$' =~ /\d+/g;
30     shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
31 };
32
33 @ISA = qw(Exporter);
34
35 @EXPORT = qw(
36   &display_date_format
37   &format_date
38   &format_date_in_iso
39 );
40
41 =head1 DESCRIPTION
42
43 C4::Circulation::Date provides routines for format dates to display in human readable forms.
44
45 =head1 FUNCTIONS
46
47 =over 2
48
49 =cut
50
51 =head2 get_date_format
52
53   $dateformat = get_date_format();
54
55 Takes no input, and returns the format that the library prefers dates displayed in
56
57
58 =cut
59
60 sub get_date_format {
61
62     # Get the database handle
63     my $dbh = C4::Context->dbh;
64     return C4::Context->preference('dateformat');
65 }
66
67 =head2 display_date_format
68
69   $displaydateformat = display_date_format();
70
71 Takes no input, and returns a string showing the format the library likes dates displayed in
72
73
74 =cut
75
76 sub display_date_format {
77     my $dateformat = get_date_format();
78
79     if ( $dateformat eq "us" ) {
80         return "mm/dd/yyyy";
81     }
82     elsif ( $dateformat eq "metric" ) {
83         return "dd/mm/yyyy";
84     }
85     elsif ( $dateformat eq "iso" ) {
86         return "yyyy-mm-dd";
87     }
88     else {
89         return
90 "Invalid date format: $dateformat. Please change in system preferences";
91     }
92 }
93
94 =head2 format_date
95
96   $formatteddate = format_date($date);
97
98 Takes a date, from mysql and returns it in the format specified by the library
99 This is less flexible than C4::Date::format_date, which can handle dates of many formats 
100 if you need that flexibility use C4::Date, if you are just using it to format the output from mysql as
101 in circulation.pl use this one, it is much faster.
102 =cut
103
104
105 sub format_date {
106     my $olddate = shift;
107     my $newdate;
108
109     if ( !$olddate ) {
110         return "";
111     }
112
113     my $dateformat = get_date_format();
114
115     if ( $dateformat eq "us" ) {
116     my @datearray=split('-',$olddate);
117     $newdate = "$datearray[1]/$datearray[2]/$datearray[0]";
118     }
119     elsif ( $dateformat eq "metric" ) {
120     my @datearray=split('-',$olddate);
121     $newdate = "$datearray[2]/$datearray[1]/$datearray[0]";
122     }
123     elsif ( $dateformat eq "iso" ) {
124         $newdate = $olddate;
125     }
126     else {
127         return
128 "Invalid date format: $dateformat. Please change in system preferences";
129     }
130 }
131
132 1;