LP#1635737: Unit tests for DST and date math
authorMike Rylander <mrylander@gmail.com>
Tue, 6 Nov 2018 20:27:23 +0000 (15:27 -0500)
committerDan Wells <dbw2@calvin.edu>
Wed, 7 Nov 2018 14:09:46 +0000 (09:09 -0500)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/t/14-OpenILS-Utils.t

index 636d2ab..81cf90f 100644 (file)
@@ -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);