Ensure our dates line up feature/automatic_hours_2_7
authorDan Scott <dscott@laurentian.ca>
Thu, 19 Feb 2015 21:24:42 +0000 (16:24 -0500)
committerDan Scott <dscott@laurentian.ca>
Thu, 19 Feb 2015 21:24:42 +0000 (16:24 -0500)
Even if it's Tuesday and Monday is a long way off, at
least we'll be consistent rather than getting 00:00:00 - 00:00:00
for a few days in the middle of the week!

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/support-scripts/parse_library_hours

index 67ffc40..bc92412 100644 (file)
@@ -60,18 +60,46 @@ $ua->timeout(20);
 # In DateTime->dow land, 1 = Monday
 my $dow = DateTime->now( time_zone => 'local' )->set_time_zone('floating')->dow;
 
-my $mon = DateTime->now( time_zone => 'local' )->set_time_zone('floating')->add(days => determine_date(1, $dow))->ymd;
-my $tue = DateTime->now( time_zone => 'local' )->set_time_zone('floating')->add(days => determine_date(2, $dow))->ymd;
-my $wed = DateTime->now( time_zone => 'local' )->set_time_zone('floating')->add(days => determine_date(3, $dow))->ymd;
-my $thu = DateTime->now( time_zone => 'local' )->set_time_zone('floating')->add(days => determine_date(4, $dow))->ymd;
-my $fri = DateTime->now( time_zone => 'local' )->set_time_zone('floating')->add(days => determine_date(5, $dow))->ymd;
-my $sat = DateTime->now( time_zone => 'local' )->set_time_zone('floating')->add(days => determine_date(6, $dow))->ymd;
-my $sun = DateTime->now( time_zone => 'local' )->set_time_zone('floating')->add(days => determine_date(7, $dow))->ymd;
-
-# Hack to prevent Sunday from being less than Monday, which returns all closed hours :/
-if ($sun lt $mon) {
-    $sun = DateTime->now( time_zone => 'local' )->set_time_zone('floating')->add(days => (7 + 7 - $dow))->ymd;
-}
+my $mon = DateTime->now( time_zone => 'local' )->set_time_zone('floating')->add(days => determine_date(1, $dow));
+
+my $tue = DateTime->new(
+    year => $mon->year,
+    month => $mon->month,
+    day => $mon->day
+)->add(days => 1)->ymd;
+
+my $wed = DateTime->new(
+    year => $mon->year,
+    month => $mon->month,
+    day => $mon->day
+)->add(days => 2)->ymd;
+
+my $thu = DateTime->new(
+    year => $mon->year,
+    month => $mon->month,
+    day => $mon->day
+)->add(days => 3)->ymd;
+
+my $fri = DateTime->new(
+    year => $mon->year,
+    month => $mon->month,
+    day => $mon->day
+)->add(days => 4)->ymd;
+
+my $sat = DateTime->new(
+    year => $mon->year,
+    month => $mon->month,
+    day => $mon->day
+)->add(days => 5)->ymd;
+
+my $sun = DateTime->new(
+    year => $mon->year,
+    month => $mon->month,
+    day => $mon->day
+)->add(days => 6)->ymd;
+
+$mon = $mon->ymd;
+
 
 my $baseUrl = 'http://laurentian.ca/sites/all/themes/lul/templates/includes/feeds/json.librarycal.php';
 $baseUrl .= "?lang=en&start=$mon&end=$sun";