Subject: | Canada Day isn't always 7/1, Christmas and Boxing Day need to be shifted too |
Your code always sets Canada Day to 7/1. You should set it to the day you actually have off from work (e.g. the Mon if it falls on Sat or Sun):
Ref:
Under the federal Holidays Act,[12] Canada Day is observed on July 1, unless that date falls on a Sunday, in which case July 2 is the statutory holiday, although celebratory events generally take place on July 1, even though it is not the legal holiday.[13] If it falls on a Saturday, any businesses normally closed that day will generally dedicate the following Monday as a day off.
See http://en.wikipedia.org/wiki/Canada_Day
Your code always sets Christmas to 12/25 and Boxing Day to 12/26. If Christmas falls on a Saturday, then the Christmas Holiday is on the following Monday and Boxing Day is on the following Tuesday. If Christmas falls on a Sunday, then it's celebrated on the following Monday. If Boxing Day falls on a Saturday, then it's celebrated on the following Monday. See http://en.wikipedia.org/wiki/Boxing_Day
Fix:
*** CA0_03.pm 2015-01-01 11:26:39.437302528 -0800
--- CA.pm 2015-01-01 12:14:36.683503909 -0800
***************
*** 79,85 ****
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
! our $VERSION = '0.03';
=head1 FUNCTIONS / METHODS
--- 79,85 ----
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
! our $VERSION = '0.04';
=head1 FUNCTIONS / METHODS
***************
*** 716,721 ****
--- 716,739 ----
return $day + $delta_days;
}
+ # _round_to_monday
+ #
+ # accepts: year, month, day for a given date
+ # returns: day unless day is a Sat/Sun, then the next Mon
+ sub _round_to_monday {
+ my $year = shift;
+ my $month = shift;
+ my $day = shift;
+
+ my $dt = DateTime->new(year => $year, month => $month, day => $day);
+
+ my $delta_days = (8 - $dt->dow());
+ $delta_days = 0 if($delta_days > 2);
+
+ return $day + $delta_days;
+ }
+
+
### holiday date calculating functions
#
# these all take one parameter ($year) and return a DateTime object
***************
*** 837,843 ****
return DateTime->new(
year => $year,
month => 7,
! day => 1,
);
}
--- 855,861 ----
return DateTime->new(
year => $year,
month => 7,
! day => _round_to_monday($year, 7, 1)
);
}
***************
*** 917,933 ****
return DateTime->new(
year => $year,
month => 12,
! day => 25,
);
}
sub _boxing_day {
my $year = shift;
! return DateTime->new(
year => $year,
! month => 12,
! day => 26,
);
}
--- 935,954 ----
return DateTime->new(
year => $year,
month => 12,
! day => _round_to_monday($year, 12, 25)
);
}
sub _boxing_day {
my $year = shift;
! # Normally the day after the Christmas Holiday, except if
! # Christmas is on Friday, then our holiday is on Monday
! my $result = _christmas_day($year)->add(days=>1);
! return DateTime->new(
year => $year,
! month => 12,
! day => _round_to_monday($year, 12, $result->day())
);
}
--joe