Bug 9031: Overdue items crossing DST boundary throw invalid local time exception
[koha-ffzg.git] / Koha / Calendar.pm
index eed55cb..f6a276f 100644 (file)
@@ -72,7 +72,7 @@ sub exception_holidays {
             day       => $day,
             month     => $month,
             year      => $year,
-            time_zone => C4::Context->tz()
+            time_zone => "floating",
           )->truncate( to => 'day' );
     }
     $self->{exception_holidays} =
@@ -118,7 +118,7 @@ sub single_holidays {
                     day       => $day,
                     month     => $month,
                     year      => $year,
-                    time_zone => C4::Context->tz()
+                    time_zone => 'floating',
                 )->truncate( to => 'day' );
                 push @ymd_arr, $dt->ymd('');
             }
@@ -235,6 +235,8 @@ sub is_holiday {
     my $day   = $localdt->day;
     my $month = $localdt->month;
 
+    #Change timezone to "floating" before doing any calculations or comparisons
+    $localdt->set_time_zone("floating");
     $localdt->truncate( to => 'day' );
 
 
@@ -294,6 +296,22 @@ sub prev_open_day {
     return $base_date;
 }
 
+sub days_forward {
+    my $self     = shift;
+    my $start_dt = shift;
+    my $num_days = shift;
+
+    return $start_dt unless $num_days > 0;
+
+    my $base_dt = $start_dt->clone();
+
+    while ($num_days--) {
+        $base_dt = $self->next_open_day($base_dt);
+    }
+
+    return $base_dt;
+}
+
 sub days_between {
     my $self     = shift;
     my $start_dt = shift;
@@ -309,7 +327,7 @@ sub days_between {
 
     # start and end should not be closed days
     my $days = $start_dt->delta_days($end_dt)->delta_days;
-    for (my $dt = $start_dt->clone();
+    for (my $dt = $start_dt->clone()->set_time_zone('floating');
         $dt <= $end_dt;
         $dt->add(days => 1)
     ) {
@@ -333,7 +351,7 @@ sub hours_between {
     # take into account open/close times then it would be a duration
     # of library open hours
     my $skipped_days = 0;
-    for (my $dt = $start_dt->clone();
+    for (my $dt = $start_dt->clone()->set_time_zone('floating');
         $dt <= $end_dt;
         $dt->add(days => 1)
     ) {