Bug 9031: Unit tests for DST crossing in (days|hours)_between
authorNick Clemens <nick@bywatersolutions.com>
Fri, 7 Jul 2017 13:03:39 +0000 (13:03 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 27 Oct 2017 17:09:03 +0000 (14:09 -0300)
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Without the patch for Calendar.pm, this crashes on:
Invalid local time for date in time zone: America/New_York

But even with the original change to Calendar.pm, I would see:
Invalid local time for date in time zone: Europe/Amsterdam
Adding a follow-up for that.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Calendar.t

index d443f11..751cd86 100644 (file)
 
 use Modern::Perl;
 
-use Test::More tests => 5;
+use Test::More tests => 6;
 use t::lib::TestBuilder;
 
 use DateTime;
 use Koha::Caches;
 use Koha::DateUtils;
+use POSIX qw(tzset);
 
 use_ok('Koha::Calendar');
 
@@ -66,4 +67,20 @@ is($forwarded_dt->ymd, $today->ymd, '0 day should return start dt');
 $forwarded_dt = $calendar->days_forward($today, -2);
 is($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt');
 
+subtest 'crossing_DST' => sub {
+
+    plan tests => 2;
+
+    $ENV{TZ} = 'America/New_York';
+    tzset;
+    my $tz = DateTime::TimeZone->new( name => 'local' );
+    my $start_date = dt_from_string( "2016-03-09 02:29:00",undef,$tz );
+    my $end_date = dt_from_string("2017-01-01");
+    my $days_between = $calendar->days_between($start_date,$end_date);
+    is($days_between->{days}, 298, "Days calculated correctly");
+    my $hours_between = $calendar->hours_between($start_date,$end_date);
+    is($hours_between->{minutes}, 428671, "Hours (in minutes) calculated correctly");
+
+};
+
 $schema->storage->txn_rollback();