[Bps-public-commit] Business-Hours branch, master, updated. 0.10_01-5-g0f66b8a

Jim Brandt jbrandt at bestpractical.com
Fri Jan 11 14:03:40 EST 2019


The branch, master has been updated
       via  0f66b8a0e793c1b863c243dab7db6062274c5ceb (commit)
      from  2f2fb42a4aea85af5bc88fb0b36613829db9d71e (commit)

Summary of changes:
 lib/Business/Hours.pm | 3 +++
 1 file changed, 3 insertions(+)

- Log -----------------------------------------------------------------
commit 0f66b8a0e793c1b863c243dab7db6062274c5ceb
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Jan 11 13:54:51 2019 -0500

    Explicitly set 4 digit years when using localtime
    
    As noted in perldoc -f localtime, when using year it's
    best to add 1900 to get an explicit 4 digit year rather
    than relying on 2 digit year algorithms to guess what you
    mean.
    
    Starting after 2018-12-31, 2 digit guessing broke completely
    for some years, causing test failures in Business::Hours.
    
    Explicitly set a 4 digit year to avoid these issues.
    
    Don't switch to Time::Local::timelocal_modern yet since it was added in
    June 2018 and may not be available on all systems yet, specifically
    systems relying on packaged perl modules.

diff --git a/lib/Business/Hours.pm b/lib/Business/Hours.pm
index ee575b9..270981e 100644
--- a/lib/Business/Hours.pm
+++ b/lib/Business/Hours.pm
@@ -272,6 +272,7 @@ sub for_timespan {
     # jump back to the first day (Sunday) of the last week before the period
     # began.
     my @start        = localtime( $args{'Start'} );
+    $start[5] += 1900;  # Set 4 digit year, see perldoc localtime
     my $month        = $start[4];
     my $year         = $start[5];
     my $first_sunday = $start[3] - $start[6];
@@ -320,6 +321,7 @@ sub for_timespan {
 
         my @today = (localtime($week_start))[3, 4, 5];
         $today[0]--; # compensate next increment
+        $today[2] += 1900;  # Set 4 digit year
 
         # foreach day in the week, find that day's business hours in
         # seconds since the epoch.
@@ -352,6 +354,7 @@ sub for_timespan {
     if ( my @holidays = $self->holidays ) {
         my $start_year = $year;
         my $end_year = (localtime $args{'End'})[5];
+        $end_year += 1900;  # Set 4 digit year
         foreach my $holiday (@holidays) {
             my ($year, $month, $date) = ($holiday =~ /^(?:(\d\d\d\d)\D)?(\d\d)\D(\d\d)$/);
             $month--;

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list