From 7abe3e03a447c7f5ec49446feac343b2c724c9e7 Mon Sep 17 00:00:00 2001
From: miker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Mon, 26 Oct 2009 15:50:41 +0000
Subject: [PATCH] make the date math a bit more maintainable

git-svn-id: svn://svn.open-ils.org/ILS/trunk@14607 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 .../perlmods/OpenILS/Application/Trigger/Validator.pm  | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm
index df50636704..f0906b8f30 100644
--- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm
+++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm
@@ -27,15 +27,15 @@ sub MaxPassiveDelayAge {
 
     my $delay_field_ts = DateTime::Format::ISO8601->new->parse_datetime(clense_ISO8601($target->$delay_field()));
 
-    # the cutoff date is today - delay - age.  This is also true for negative delays.
-    # For example, today - "7 days" - "1 day" == 8 days ago.  For a 7-day delay, you would
-    # not validate if the date of the object is 8 or more days old.
-    my $max_date = DateTime->now;
-    $max_date->subtract( seconds => interval_to_seconds( $env->{event}->event_def->delay ) );
-    $max_date->subtract( seconds => interval_to_seconds( $env->{params}->{max_delay_age} ) );
-
-    return 0 if $delay_field_ts <= $max_date;
-    return 1;
+    # the cutoff date is the target timestamp + the delay + the max_delay_age
+    # This is also true for negative delays. For example:
+    #    due_date + "-3 days" + "1 day" == -2 days old.
+    $delay_field_ts
+        ->add( seconds => interval_to_seconds( $env->{event}->event_def->delay ) )
+        ->add( seconds => interval_to_seconds( $env->{params}->{max_delay_age} ) );
+
+    return 1 if $delay_field_ts > DateTime->now;
+    return 0;
 }
 
 sub CircIsOverdue {
-- 
2.11.0