[open-ils-commits] [GIT] Evergreen ILS branch rel_3_2 updated. d96d5b6bcb279f60b4add125eb33eefa3417fffb

Evergreen Git git at git.evergreen-ils.org
Wed Nov 7 09:11:55 EST 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, rel_3_2 has been updated
       via  d96d5b6bcb279f60b4add125eb33eefa3417fffb (commit)
       via  b5357b0283c37ce12d161186f1092d138752e4f4 (commit)
       via  8520c3257a71444a9068e1c9de344c2010b2af02 (commit)
       via  36581e75999f7fda8705e203a4e299988662fa54 (commit)
       via  479361d70a31562cb045d14742c85b5440491067 (commit)
      from  f8473b18091b355cc9452ae7adeb5214fa997f7a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d96d5b6bcb279f60b4add125eb33eefa3417fffb
Author: Bill Erickson <berickxx at gmail.com>
Date:   Tue Nov 6 16:22:43 2018 -0500

    LP#1635737 Due date DST-aware thinko fix
    
    Minor code refactor to fix thinko and syntax issues.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
index fab7796..73d69ef 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
@@ -2396,11 +2396,11 @@ sub create_due_date {
     ) || 'local';
 
     my $due_date = $start_time ?
-        DateTime->now(time_zone => $tz) :
-        $due_date = DateTime::Format::ISO8601
+        DateTime::Format::ISO8601
             ->new
             ->parse_datetime(clean_ISO8601($start_time))
-            ->set_time_zone($tz);
+            ->set_time_zone($tz) :
+        DateTime->now(time_zone => $tz);
 
     # add the circ duration
     $due_date->add(seconds => OpenILS::Utils::DateTime->interval_to_seconds($duration, $due_date));

commit b5357b0283c37ce12d161186f1092d138752e4f4
Author: Mike Rylander <mrylander at gmail.com>
Date:   Mon Jul 31 15:55:34 2017 -0400

    LP#1635737 Apply DST-aware timezone to context dates
    
    Do our best to enforce the rule required by OpenSRF's interval_to_seconds
    that when a context date is in use, and you care about DST awareness, you
    must set the timezone to a DST-aware value, e.g., 'America/New_York'. In
    most situations, 'local' will suffice for this, as the server is typically
    configured with a DST-aware timezone in its environment.  However, we will
    look for an org unit setting called 'lib.timezone' and use that where we
    can.  See LP#1705524 for info on that setting.
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>
    
    Conflicts:
    	Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
    	Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/NonCat.pm
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Bill Erickson <berickxx at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
index 990c3a7..fab7796 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
@@ -2387,15 +2387,30 @@ sub apply_modified_due_date {
 sub create_due_date {
     my( $self, $duration, $date_ceiling, $force_date, $start_time ) = @_;
 
-    # for now, use the server timezone.  TODO: use workstation org timezone
-    my $due_date = DateTime->now(time_zone => 'local');
-    $due_date = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($start_time)) if $start_time;
+    # Look up circulating library's TZ, or else use client TZ, falling
+    # back to server TZ
+    my $tz = $U->ou_ancestor_setting_value(
+        $self->circ_lib,
+        'lib.timezone',
+        $self->editor
+    ) || 'local';
+
+    my $due_date = $start_time ?
+        DateTime->now(time_zone => $tz) :
+        $due_date = DateTime::Format::ISO8601
+            ->new
+            ->parse_datetime(clean_ISO8601($start_time))
+            ->set_time_zone($tz);
 
     # add the circ duration
     $due_date->add(seconds => OpenILS::Utils::DateTime->interval_to_seconds($duration, $due_date));
 
     if($date_ceiling) {
-        my $cdate = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($date_ceiling));
+        my $cdate = DateTime::Format::ISO8601
+            ->new
+            ->parse_datetime(clean_ISO8601($date_ceiling))
+            ->set_time_zone($tz);
+
         if ($cdate > DateTime->now and ($cdate < $due_date or $U->is_true( $force_date ))) {
             $logger->info("circulator: overriding due date with date ceiling: $date_ceiling");
             $due_date = $cdate;
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/NonCat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/NonCat.pm
index cdf9a6f..da23bf3 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/NonCat.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/NonCat.pm
@@ -186,7 +186,16 @@ sub noncat_due_date {
     my $otype = $e->retrieve_config_non_cataloged_type($circ->item_type) 
         or return $e->die_event;
 
-    my $duedate = $_dt_parser->parse_datetime( clean_ISO8601($circ->circ_time) );
+    my $tz = $U->ou_ancestor_setting_value(
+        $circ->circ_lib,
+        'lib.timezone',
+        $self->editor
+    ) || 'local';
+
+    my $duedate = $_dt_parser
+        ->parse_datetime( clean_ISO8601($circ->circ_time) )
+        ->set_time_zone( $tz );
+
     $duedate = $duedate
         ->add( seconds => interval_to_seconds($otype->circ_duration, $duedate) )
         ->strftime('%FT%T%z');

commit 8520c3257a71444a9068e1c9de344c2010b2af02
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Fri Jul 21 14:28:16 2017 -0400

    LP#1635737 Use new OpenSRF interval_to_seconds() context
    
    Use the optional context for interval_to_seconds() to account for the
    variable length of duration components.  For example, "1 day" may be
    shorter or longer than 24 hours during a time change event, "1 month"
    may be shorter or longer depending on which month it is currently, etc.
    
    Also, remove some timestamp munging, as that happens within
    interval_to_seconds() already.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>
    
    Conflicts:
    	Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Bill Erickson <berickxx at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
index bf5dd0e..990c3a7 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
@@ -2387,16 +2387,12 @@ sub apply_modified_due_date {
 sub create_due_date {
     my( $self, $duration, $date_ceiling, $force_date, $start_time ) = @_;
 
-    # if there is a raw time component (e.g. from postgres), 
-    # turn it into an interval that interval_to_seconds can parse
-    $duration =~ s/(\d{2}):(\d{2}):(\d{2})/$1 h $2 m $3 s/o;
-
     # for now, use the server timezone.  TODO: use workstation org timezone
     my $due_date = DateTime->now(time_zone => 'local');
     $due_date = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($start_time)) if $start_time;
 
     # add the circ duration
-    $due_date->add(seconds => OpenILS::Utils::DateTime->interval_to_seconds($duration));
+    $due_date->add(seconds => OpenILS::Utils::DateTime->interval_to_seconds($duration, $due_date));
 
     if($date_ceiling) {
         my $cdate = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($date_ceiling));
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/NonCat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/NonCat.pm
index 0d576cf..cdf9a6f 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/NonCat.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/NonCat.pm
@@ -188,7 +188,7 @@ sub noncat_due_date {
 
     my $duedate = $_dt_parser->parse_datetime( clean_ISO8601($circ->circ_time) );
     $duedate = $duedate
-        ->add( seconds => interval_to_seconds($otype->circ_duration) )
+        ->add( seconds => interval_to_seconds($otype->circ_duration, $duedate) )
         ->strftime('%FT%T%z');
 
     my $offset = $U->storagereq(

commit 36581e75999f7fda8705e203a4e299988662fa54
Author: Mike Rylander <mrylander at gmail.com>
Date:   Tue Nov 6 15:27:23 2018 -0500

    LP#1635737: Unit tests for DST and date math
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Bill Erickson <berickxx at gmail.com>

diff --git a/Open-ILS/src/perlmods/t/14-OpenILS-Utils.t b/Open-ILS/src/perlmods/t/14-OpenILS-Utils.t
index 636d2ab..81cf90f 100644
--- a/Open-ILS/src/perlmods/t/14-OpenILS-Utils.t
+++ b/Open-ILS/src/perlmods/t/14-OpenILS-Utils.t
@@ -14,7 +14,7 @@
 # truckload to verify that everything would continue to work if
 # we turn it on across the board.
 
-use Test::More tests => 43;
+use Test::More tests => 47;
 use Test::Warn;
 use DateTime::TimeZone;
 use DateTime::Format::ISO8601;
@@ -121,6 +121,23 @@ is (OpenILS::Utils::DateTime::interval_to_seconds('1 hour'), 3600);
 is (OpenILS::Utils::DateTime::interval_to_seconds('1 day'), 86400);
 is (OpenILS::Utils::DateTime::interval_to_seconds('1 week'), 604800);
 is (OpenILS::Utils::DateTime::interval_to_seconds('1 month'), 2628000);
+
+# With context, no DST change, with timezone
+is (OpenILS::Utils::DateTime::interval_to_seconds('1 month',
+    DateTime::Format::ISO8601->new->parse_datetime('2017-02-04T23:59:59-04')->set_time_zone("America/New_York")), 2419200);
+
+# With context, with DST change, with timezone
+is (OpenILS::Utils::DateTime::interval_to_seconds('1 month',
+    DateTime::Format::ISO8601->new->parse_datetime('2017-02-14T23:59:59-04')->set_time_zone("America/New_York")), 2415600);
+
+# With context, no DST change, no time zone
+is (OpenILS::Utils::DateTime::interval_to_seconds('1 month',
+    DateTime::Format::ISO8601->new->parse_datetime('2017-02-04T23:59:59-04')), 2419200);
+
+# With context, with DST change, no time zone (so, not DST-aware)
+is (OpenILS::Utils::DateTime::interval_to_seconds('1 month',
+    DateTime::Format::ISO8601->new->parse_datetime('2017-02-14T23:59:59-04')), 2419200);
+
 is (OpenILS::Utils::DateTime::interval_to_seconds('1 year'), 31536000);
 is (OpenILS::Utils::DateTime::interval_to_seconds('1 year 1 second'), 31536001);
 

commit 479361d70a31562cb045d14742c85b5440491067
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Tue Nov 6 15:13:47 2018 -0500

    LP#1635737 Add optional context to interval_to_seconds
    
    Any given interval (e.g. "1 month") can be a different amount of
    seconds depending on the context (i.e. "1 month" after February 1 is
    March 1, but "1 month" after March 1 is April 1, yet March is longer
    than February).  This affects months all the time, but also can
    affect days, hours, and even seconds once you consider DST and "leap"
    times.
    
    By giving an optional context to interval_to_seconds, you can find
    the true number of seconds in, for example, "1 month", when starting
    from "February 1" (the context).
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>
    Signed-off-by: Bill Erickson <berickxx at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/DateTime.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/DateTime.pm
index 05f0883..1da0951 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/DateTime.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/DateTime.pm
@@ -7,6 +7,7 @@ use FileHandle;
 use Digest::MD5 qw(md5 md5_hex md5_base64);
 use Exporter;
 use DateTime;
+use DateTime::Duration;
 use DateTime::Format::ISO8601;
 use DateTime::TimeZone;
 
@@ -53,7 +54,7 @@ sub AUTOLOAD {
 	return $self->{$name};
 }
 
-=head2 $thing->interval_to_seconds('interval') OR interval_to_seconds('interval')
+=head2 $thing->interval_to_seconds('interval', ['context']) OR interval_to_seconds('interval', ['context'])
 
 =head2 $thing->seconds_to_interval($seconds) OR seconds_to_interval($seconds)
 
@@ -98,31 +99,61 @@ for months (really (365 * 1d)/12 ... that may get smarter, though)
 
 for years (this is 365 * 1d)
 
+Passing in an optional 'context' (DateTime object) will give you the number of seconds for the passed interval *starting from* the given date (e.g. '1 month' from a context of 'February 1' would return the number of seconds needed to get to 'March 1', not the generic calculation of 1/12 of the seconds in a normal year).
+
 =back
 
 =cut
 sub interval_to_seconds {
-	my $self = shift;
-        my $interval = shift || $self;
+    my $class = shift; # throwaway
+    my $interval = ($class eq __PACKAGE__) ? shift : $class;
+    my $context = shift;
 
-	$interval =~ s/(\d{2}):(\d{2}):(\d{2})/ $1 h $2 min $3 s /go;
+    $interval =~ s/(\d{2}):(\d{2}):(\d{2})/ $1 h $2 min $3 s /go;
 
-        $interval =~ s/and/,/g;
-        $interval =~ s/,/ /g;
+    $interval =~ s/and/,/g;
+    $interval =~ s/,/ /g;
 
-        my $amount = 0;
+    my $amount;
+    if ($context) {
+        my $dur = DateTime::Duration->new();
+        while ($interval =~ /\s*([\+-]?)\s*(\d+)\s*(\w+)\s*/g) {
+            my ($sign, $count, $type) = ($1, $2, $3);
+            my $func = ($sign eq '-') ? 'subtract' : 'add';
+            if ($type =~ /^s/) {
+                $type = 'seconds';
+            } elsif ($type =~ /^m(?!o)/oi) {
+                $type = 'minutes';
+            } elsif ($type =~ /^h/) {
+                $type = 'hours';
+            } elsif ($type =~ /^d/oi) {
+                $type = 'days';
+            } elsif ($type =~ /^w/oi) {
+                $type = 'weeks';
+            } elsif ($type =~ /^mo/io) {
+                $type = 'months';
+            } elsif ($type =~ /^y/oi) {
+                $type = 'years';
+            }
+            $dur->$func($type => $count);
+        }
+        my $later = $context->clone->add_duration($dur);
+        $amount = $later->subtract_datetime_absolute($context)->in_units( 'seconds' );
+    } else {
+        $amount = 0;
         while ($interval =~ /\s*([\+-]?)\s*(\d+)\s*(\w+)\s*/g) {
-		my ($sign, $count, $type) = ($1, $2, $3);
-		$count = "$sign$count" if ($sign);
-                $amount += $count if ($type =~ /^s/);
-                $amount += 60 * $count if ($type =~ /^m(?!o)/oi);
-                $amount += 60 * 60 * $count if ($type =~ /^h/);
-                $amount += 60 * 60 * 24 * $count if ($type =~ /^d/oi);
-                $amount += 60 * 60 * 24 * 7 * $count if ($type =~ /^w/oi);
-                $amount += ((60 * 60 * 24 * 365)/12) * $count if ($type =~ /^mo/io);
-                $amount += 60 * 60 * 24 * 365 * $count if ($type =~ /^y/oi);
+            my ($sign, $count, $type) = ($1, $2, $3);
+            $count = "$sign$count" if ($sign);
+            $amount += $count if ($type =~ /^s/);
+            $amount += 60 * $count if ($type =~ /^m(?!o)/oi);
+            $amount += 60 * 60 * $count if ($type =~ /^h/);
+            $amount += 60 * 60 * 24 * $count if ($type =~ /^d/oi);
+            $amount += 60 * 60 * 24 * 7 * $count if ($type =~ /^w/oi);
+            $amount += ((60 * 60 * 24 * 365)/12) * $count if ($type =~ /^mo/io);
+            $amount += 60 * 60 * 24 * 365 * $count if ($type =~ /^y/oi);
         }
-        return $amount;
+    }
+    return $amount;
 }
 
 sub seconds_to_interval {

-----------------------------------------------------------------------

Summary of changes:
 .../lib/OpenILS/Application/Circ/Circulate.pm      |   29 ++++++---
 .../lib/OpenILS/Application/Circ/NonCat.pm         |   13 +++-
 .../src/perlmods/lib/OpenILS/Utils/DateTime.pm     |   65 ++++++++++++++-----
 Open-ILS/src/perlmods/t/14-OpenILS-Utils.t         |   19 ++++++-
 4 files changed, 97 insertions(+), 29 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list