Module to format dates in the correct manner.
authorwolfpac444 <wolfpac444>
Wed, 26 Mar 2003 02:48:59 +0000 (02:48 +0000)
committerwolfpac444 <wolfpac444>
Wed, 26 Mar 2003 02:48:59 +0000 (02:48 +0000)
C4/Date.pm [new file with mode: 0644]

diff --git a/C4/Date.pm b/C4/Date.pm
new file mode 100644 (file)
index 0000000..5e3a6cf
--- /dev/null
@@ -0,0 +1,90 @@
+#!/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
+);
+
+
+
+sub get_date_format
+{
+       #Get the database handle
+       my $dbh = C4::Context->dbh;
+
+       #Query the database to get the dateformat
+       my $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='dateformat'");
+
+       $sth->execute();
+
+       my ($dateformat) = $sth->fetchrow;
+       
+       return $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 format_date
+{
+       my $olddate = shift;
+       my $newdate;
+
+       my $dateformat = get_date_format();
+       
+       if ( $dateformat eq "us" )
+       {
+               $olddate = ParseDate($olddate);
+               $newdate = UnixDate($olddate,'%m/%d/%Y');
+       }
+       elsif ( $dateformat eq "metric" )
+       {
+               $olddate = ParseDate($olddate);
+               $newdate = UnixDate($olddate,'%d/%m/%Y');
+       }
+       elsif ( $dateformat eq "iso" )
+       {
+               $olddate = ParseDate($olddate);
+               $newdate = UnixDate($olddate,'%Y-%m-%d');
+       }
+       else
+       {
+               return "Invalid date format: $dateformat. Please change in system preferences";
+       }
+}
+
+1;