From 59682e3fa57ca03ffc78704b22f68795b9caa30e Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Mon, 31 Jul 2017 12:53:59 -0400 Subject: [PATCH] LP#1635737: Unit tests for DST and date math Signed-off-by: Mike Rylander --- src/perl/t/09-Utils-interval_to_seconds.t | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/perl/t/09-Utils-interval_to_seconds.t b/src/perl/t/09-Utils-interval_to_seconds.t index 4328fe2..5e4318b 100644 --- a/src/perl/t/09-Utils-interval_to_seconds.t +++ b/src/perl/t/09-Utils-interval_to_seconds.t @@ -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); -- 2.11.0