Description: Improve Debian reproducibility by testing in UTC
 This patch ensures that where necessary, tests are carried out in the UTC
 timezone. We also substitute the use of localtime() with gmtime().
Author: Nick Morrott <knowledgejunkie@gmail.com>
Forwarded: not-needed
Last-Update: 2018-08-29
---
--- a/t/1-business-hours.t
+++ b/t/1-business-hours.t
@@ -1,5 +1,6 @@
 use strict;
 use warnings;
+use DateTime;
 use Test::More tests => 17;
 
 BEGIN { use_ok 'Business::Hours' }
@@ -8,7 +9,7 @@
     my $hours = Business::Hours->new();
     is(ref($hours), 'Business::Hours');
     # how many business hours were there in the first week.
-    my $hours_span = $hours->for_timespan(Start => '0', End => ( (86400 * 7) - 1));
+    my $hours_span = $hours->for_timespan(Start => time(), End => time() + (86400 * 7) - 1);
     is(ref($hours_span), 'Set::IntSpan');
 
     # Are there 45 working hours
@@ -20,7 +21,7 @@
     my $hours = Business::Hours->new();
     is(ref($hours), 'Business::Hours');
     # how many business hours were there in the first week.
-    my $seconds = $hours->between( 0, ( (86400 * 7) - 1 ) );
+    my $seconds = $hours->between( time(), time() + (86400 * 7) - 1);
     ok( $seconds, "Got seconds" );
 
     # Are there 45 working hours
@@ -34,31 +35,49 @@
     my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
     my $starttime;
 
-    # pick a date that's during business hours
-    $starttime = 0;
-    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+    # Find a date that's during business hours. Keep all date/time
+    # information in UTC.
+    my $start_date = DateTime->new(
+	year => 2018,
+	month => 1,
+	day => 1,
+	hour => 0,
+	minute => 0,
+	time_zone => 'UTC',
+    );
+    $starttime = $start_date->epoch;
+    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($starttime);
     while ($wday == 0  || $wday == 6) {
 	$starttime += ( 24 * 60 * 60);
-	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($starttime);
     }
     while ( $hour < 9 || $hour >= 18 ) {
 	$starttime += ( 4 * 60);
-	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($starttime);
     }
 
     $time = $hours->first_after( $starttime );
     is($time, ( $starttime ));
 
-    # pick a date that's not during business hours
-    $starttime = 0;
-    my ($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
+    # Find a date that's not during business hours. Keep all date/time
+    # information in UTC.
+    $start_date = DateTime->new(
+	year => 2018,
+	month => 1,
+	day => 1,
+	hour => 0,
+	minute => 0,
+	time_zone => 'UTC',
+    );
+    $starttime = $start_date->epoch;
+    my ($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = gmtime($starttime);
     while ( $xwday != 0 ) {
 	$starttime += ( 24 * 60 * 60);
-	($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
+	($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = gmtime($starttime);
     }
 
     $time = $hours->first_after( $starttime );
-    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
+    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($time);
     is($wday, $xwday+1);
     is($hour, 9);
     is($min, 0);
@@ -70,16 +89,34 @@
     my $hours = Business::Hours->new();
 
     my ($start, $time, $span);
-    # pick a date that's during business hours
-    $start = (20 * 60 * 60);
+    # Find a date that's during business hours. Keep all date/time
+    # information in UTC.
+    my $start_date = DateTime->new(
+        year => 2018,
+        month => 1,
+        day => 8,
+        hour => 9,
+        minute => 0,
+        time_zone => 'UTC',
+    );
+    $start = $start_date->epoch;
     $time = $hours->add_seconds( $start, 30 * 60);
     $span = $hours->for_timespan(Start => $start, End => $time);
 
     # the first second is a business second, too
     is(cardinality $span, (30 * 60)+1);
 
-    # pick a date that's not during business hours
-    $start = 0;
+    # Find a date that's not during business hours. Keep all date/time
+    # information in UTC.
+    $start_date = DateTime->new(
+        year => 2018,
+        month => 1,
+        day => 7,
+        hour => 9,
+        minute => 0,
+        time_zone => 'UTC',
+    );
+    $start = $start_date->epoch;
     $time = $hours->add_seconds( $start, 30 * 60);
     $span = $hours->for_timespan(Start => $start, End => $time);
 
@@ -95,7 +132,7 @@
 			      End   => undef,
 			  },
 			  1 => {
-			      Name  => 'Monday',	
+			      Name  => 'Monday',
 			      Start => '9:00',
 			      End   => '18:00',
 			      Breaks => [
@@ -106,7 +143,7 @@
 					 ],
 			  },
 			  2 => {
-			      Name  => 'Tuesday', 
+			      Name  => 'Tuesday',
 			      Start => '9:00',
 			      End   => '18:00',
 			      Breaks => [
@@ -158,7 +195,7 @@
     $hours->business_hours(%BUSINESS_HOURS);
     is(ref($hours), 'Business::Hours');
     # how many business hours were there in the first week.
-    my $hours_span = $hours->for_timespan(Start => '0', End => ( (86400 * 7) - 1));
+    my $hours_span = $hours->for_timespan(Start => time(), End => time() + (86400 * 7) - 1);
     is(ref($hours_span), 'Set::IntSpan');
 
     # Are there 40 working hours
