[OpenSRF-GIT] OpenSRF branch master updated. 716b674a5197f9ec70091c9f3dfa3eabca3bbe9d

Evergreen Git git at git.evergreen-ils.org
Mon Jul 31 15:15:31 EDT 2017


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 "OpenSRF".

The branch, master has been updated
       via  716b674a5197f9ec70091c9f3dfa3eabca3bbe9d (commit)
       via  0484c673577c49a552af861364caac03ef187f5e (commit)
      from  316f58375c40087bfae32234c4dd3817260831e5 (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 716b674a5197f9ec70091c9f3dfa3eabca3bbe9d
Author: Mike Rylander <mrylander at gmail.com>
Date:   Mon Jul 31 15:15:09 2017 -0400

    Revert "LP#1635737 Add optional context to interval_to_seconds"
    
    This reverts commit a481100ef9d5bd9eaad5a87ce29776cb07a8687c.

diff --git a/src/perl/lib/OpenSRF/Utils.pm b/src/perl/lib/OpenSRF/Utils.pm
index 90beb82..bb6858a 100644
--- a/src/perl/lib/OpenSRF/Utils.pm
+++ b/src/perl/lib/OpenSRF/Utils.pm
@@ -7,7 +7,6 @@ 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;
 
@@ -201,7 +200,7 @@ sub noo_es_time {
 }
 
 
-=head2 $thing->interval_to_seconds('interval', ['context']) OR interval_to_seconds('interval', ['context'])
+=head2 $thing->interval_to_seconds('interval') OR interval_to_seconds('interval')
 
 =head2 $thing->seconds_to_interval($seconds) OR seconds_to_interval($seconds)
 
@@ -246,61 +245,31 @@ 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 $class = shift; # throwaway
-    my $interval = ($class eq __PACKAGE__) ? shift : $class;
-    my $context = shift;
+	my $self = shift;
+        my $interval = shift || $self;
 
-    $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;
-    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;
+        my $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 {

commit 0484c673577c49a552af861364caac03ef187f5e
Author: Mike Rylander <mrylander at gmail.com>
Date:   Mon Jul 31 15:15:02 2017 -0400

    Revert "LP#1635737: Unit tests for DST and date math"
    
    This reverts commit 316f58375c40087bfae32234c4dd3817260831e5.

diff --git a/src/perl/t/09-Utils-interval_to_seconds.t b/src/perl/t/09-Utils-interval_to_seconds.t
index 2f82ea2..4328fe2 100644
--- a/src/perl/t/09-Utils-interval_to_seconds.t
+++ b/src/perl/t/09-Utils-interval_to_seconds.t
@@ -1,8 +1,6 @@
-#!perl 
+#!perl -T
 
-
-use DateTime::Format::ISO8601;
-use Test::More tests => 10;
+use Test::More tests => 9;
 
 BEGIN {
 	use_ok( 'OpenSRF::Utils' );
@@ -14,14 +12,5 @@ is (OpenSRF::Utils::interval_to_seconds('1 hour'), 3600);
 is (OpenSRF::Utils::interval_to_seconds('1 day'), 86400);
 is (OpenSRF::Utils::interval_to_seconds('1 week'), 604800);
 is (OpenSRF::Utils::interval_to_seconds('1 month'), 2628000);
-
-# With context, no DST change
-is (OpenSRF::Utils::interval_to_seconds('1 month',
-    DateTime::Format::ISO8601->new->parse_datetime('2017-02-04T23:59:59-04')), 2419200);
-
-# With context, with DST change
-is (OpenSRF::Utils::interval_to_seconds('1 month',
-    DateTime::Format::ISO8601->new->parse_datetime('2017-02-14T23:59:59-04')), 2415600);
-
 is (OpenSRF::Utils::interval_to_seconds('1 year'), 31536000);
 is (OpenSRF::Utils::interval_to_seconds('1 year 1 second'), 31536001);

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

Summary of changes:
 src/perl/lib/OpenSRF/Utils.pm             |   65 ++++++++---------------------
 src/perl/t/09-Utils-interval_to_seconds.t |   15 +------
 2 files changed, 19 insertions(+), 61 deletions(-)


hooks/post-receive
-- 
OpenSRF


More information about the opensrf-commits mailing list