LP#1635737: Unit tests for DST and date math user/miker/lp-1635737-interval_to_seconds-with-context
authorMike Rylander <mrylander@gmail.com>
Mon, 31 Jul 2017 16:53:59 +0000 (12:53 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 31 Jul 2017 19:53:32 +0000 (15:53 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
src/perl/t/09-Utils-interval_to_seconds.t

index 4328fe2..5e4318b 100644 (file)
@@ -1,6 +1,8 @@
-#!perl -T
+#!perl 
 
-use Test::More tests => 9;
+
+use DateTime::Format::ISO8601;
+use Test::More tests => 13;
 
 BEGIN {
        use_ok( 'OpenSRF::Utils' );
@@ -12,5 +14,22 @@ 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, with timezone
+is (OpenSRF::Utils::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 (OpenSRF::Utils::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 (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, no time zone (so, not DST-aware)
+is (OpenSRF::Utils::interval_to_seconds('1 month',
+    DateTime::Format::ISO8601->new->parse_datetime('2017-02-14T23:59:59-04')), 2419200);
+
 is (OpenSRF::Utils::interval_to_seconds('1 year'), 31536000);
 is (OpenSRF::Utils::interval_to_seconds('1 year 1 second'), 31536001);