use OpenSRF::Utils::Cache;
use OpenSRF::Utils::Logger qw/$logger/;
use OpenILS::Utils::ModsParser;
+use OpenSRF::Utils qw/:datetime/;
use OpenSRF::EX qw(:try);
use OpenILS::Event;
use Data::Dumper;
$e, $user_id, md5_hex($salt . $md5_pass), $pw_type);
}
+# Adds an interval amount to a date, taking variable length durations
+# into account, for example days across time changes boundaries,
+# number of days in a month, and number of days in a (leap) year.
+# If no date is provided, it defaults to NOW().
+sub add_interval {
+ my $class = shift;
+ my $interval = shift;
+ my $date = shift || DateTime->now(time_zone => 'local');
+
+ # Pass the interval value through a cycle of interval_to_seconds()
+ # and seconds_to_interval() to normalize the interval string.
+ my $seconds = OpenSRF::Utils->interval_to_seconds($interval);
+ $interval = OpenSRF::Utils->seconds_to_interval($seconds);
+
+ # Then chop the interval up into components DateTime::add() understands.
+ # ::add() expects all lower case, plural duration components.
+
+ my %parts;
+ for my $component (split(/, /, $interval)) {
+ my ($number, $part) = split(/ /, $component);
+ $part = lc($part);
+ $part .= 's' unless ($part =~ /s$/); # force plural
+ $parts{$part} = $number;
+ }
+ $date->add(\%parts);
+
+ return $date;
+}
+
1;
my $due_date = DateTime->now(time_zone => 'local');
$due_date = DateTime::Format::ISO8601->new->parse_datetime(cleanse_ISO8601($start_time)) if $start_time;
- # add the circ duration
- $due_date->add(seconds => OpenSRF::Utils->interval_to_seconds($duration));
+ $due_date = $U->add_interval($duration, $due_date);
if($date_ceiling) {
my $cdate = DateTime::Format::ISO8601->new->parse_datetime(cleanse_ISO8601($date_ceiling));