LP#1635737 Date intervals live test
authorBill Erickson <berickxx@gmail.com>
Thu, 23 Mar 2017 20:33:57 +0000 (16:33 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 19 May 2017 15:09:45 +0000 (11:09 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/live_t/22-lp1635737-date-duration-math.t [new file with mode: 0644]

diff --git a/Open-ILS/src/perlmods/live_t/22-lp1635737-date-duration-math.t b/Open-ILS/src/perlmods/live_t/22-lp1635737-date-duration-math.t
new file mode 100644 (file)
index 0000000..87506cf
--- /dev/null
@@ -0,0 +1,42 @@
+#!perl
+
+use Test::More tests => 2;
+
+diag("Test date duration addition across time change boundaries");
+
+use strict; use warnings;
+
+use OpenILS::Utils::TestUtils;
+use OpenILS::Application::AppUtils;
+my $script = OpenILS::Utils::TestUtils->new();
+
+$script->bootstrap;
+my $U = 'OpenILS::Application::AppUtils';
+
+# To ensure we're always comparing Apples to Apples, apply the 
+# same time zone to all dates tested.
+my $tz = 'America/Los_Angeles';
+
+# Testing 2016-10-10 00:05:00-0700 + 28 days which 
+# crosses the November 6 2016 time change boundary.
+my $test_date = DateTime->new(
+    year        => 2016,
+    month       => 10,
+    day         => 10,
+    hour        => 0,
+    minute      => 5, 
+    time_zone   => $tz
+);
+
+my $new_date = $U->date_plus_interval($test_date, '28 days');
+$new_date->set_time_zone($tz);
+
+is($new_date->strftime('%FT%T%z'), '2016-11-07T00:05:00-0800', 
+    'Date plus interval includes extra hour from time change');
+
+$test_date = DateTime->now(time_zone => $tz);
+$new_date = $U->date_plus_interval($test_date, '10 years');
+$new_date->set_time_zone($tz);
+
+is($new_date->day, $test_date->day, 'Days match across multiple leap years');
+