[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha/C4 Date.pm [rel_2_2]
From: |
Mason James |
Subject: |
[Koha-cvs] koha/C4 Date.pm [rel_2_2] |
Date: |
Tue, 16 Jan 2007 02:47:36 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: rel_2_2
Changes by: Mason James <sushi> 07/01/16 02:47:36
Modified files:
C4 : Date.pm
Log message:
added Tumer's new subs() from rel3, for holidays.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Date.pm?cvsroot=koha&only_with_tag=rel_2_2&r1=1.13.4.3&r2=1.13.4.4
Patches:
Index: Date.pm
===================================================================
RCS file: /sources/koha/koha/C4/Date.pm,v
retrieving revision 1.13.4.3
retrieving revision 1.13.4.4
diff -u -b -r1.13.4.3 -r1.13.4.4
--- Date.pm 16 Jan 2007 02:39:54 -0000 1.13.4.3
+++ Date.pm 16 Jan 2007 02:47:36 -0000 1.13.4.4
@@ -4,6 +4,11 @@
use strict;
use C4::Context;
+use DateTime;
+use DateTime::Format::ISO8601;
+use DateTime::Format::Strptime;
+use DateTime::Format::Duration;
+use POSIX qw(ceil floor);
use Date::Calc
qw(Parse_Date Decode_Date_EU Decode_Date_US Time_to_Date check_date);
@@ -19,6 +24,9 @@
&display_date_format
&format_date
&format_date_in_iso
+ &get_date_format_string_for_DHTMLcalendar
+ &DATE_diff &DATE_Add
+ &get_today &DATE_Add_Duration &DATE_obj &get_duration
);
sub get_date_format {
@@ -138,4 +146,77 @@
return $newdate;
}
+
+sub DATE_diff {
+## returns 1 if date1>date2 0 if date1==date2 -1 if date1<date2
+ my ( $date1, $date2 ) = @_;
+ my $dt1 = DateTime::Format::ISO8601->parse_datetime($date1);
+ my $dt2 = DateTime::Format::ISO8601->parse_datetime($date2);
+ my $diff = DateTime->compare( $dt1, $dt2 );
+ return $diff;
+}
+
+sub DATE_Add {
+## $amount in days
+ my ( $date, $amount ) = @_;
+ my $dt1 = DateTime::Format::ISO8601->parse_datetime($date);
+ $dt1->add( days => $amount );
+ return $dt1->ymd;
+}
+
+sub DATE_Add_Duration {
+## Similar as above but uses Duration object as amount --used heavily in
serials
+ my ( $date, $amount ) = @_;
+ my $dt1 = DateTime::Format::ISO8601->parse_datetime($date);
+ $dt1->add_duration($amount);
+ return $dt1->ymd;
+}
+
+sub get_today {
+ my $dt = DateTime->today;
+ return $dt->ymd;
+}
+
+sub DATE_obj {
+
+ # only send iso dates to this
+ my $date = shift;
+ my $parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d' );
+ my $newdate = $parser->parse_datetime($date);
+ return $newdate;
+}
+
+sub get_duration {
+ my $period = shift;
+
+ my $parse;
+ if ( $period =~ /ays/ ) {
+ $parse = "\%e days";
+ }
+ elsif ( $period =~ /week/ ) {
+ $parse = "\%W weeks";
+ }
+ elsif ( $period =~ /year/ ) {
+ $parse = "\%Y years";
+ }
+ elsif ( $period =~ /onth/ ) {
+ $parse = "\%m months";
+ }
+
+ my $parser = DateTime::Format::Duration->new( pattern => $parse );
+ my $duration = $parser->parse_duration($period);
+
+ return $duration;
+
+}
+
+sub DATE_subtract {
+ my ( $date1, $date2 ) = @_;
+ my $dt1 = DateTime::Format::ISO8601->parse_datetime($date1);
+ my $dt2 = DateTime::Format::ISO8601->parse_datetime($date2);
+ my $dur = $dt2->subtract_datetime_absolute($dt1); ## in
seconds
+ my $days = $dur->seconds / ( 60 * 60 * 24 );
+ return floor($days);
+}
+
1;