From 4dd0e8d2fb614d8cbc60174f078f23de9903eb49 Mon Sep 17 00:00:00 2001 From: wolfpac444 Date: Fri, 28 Mar 2003 23:08:30 +0000 Subject: [PATCH] Here we go again... --- C4/Date.pm | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/C4/Date.pm b/C4/Date.pm index 5e3a6cfdd6..59a4fcc98c 100644 --- a/C4/Date.pm +++ b/C4/Date.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -w - package C4::Date; use strict; @@ -17,10 +15,9 @@ $VERSION = 0.01; @EXPORT = qw( &display_date_format &format_date + &format_date_in_iso ); - - sub get_date_format { #Get the database handle @@ -68,16 +65,19 @@ sub format_date 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'); } @@ -87,4 +87,37 @@ sub format_date } } +sub format_date_in_iso +{ + my $olddate = shift; + my $newdate; + + 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; +} + 1; +__END__ -- 2.39.5