X-Git-Url: https://git.donarmstrong.com/?p=deb_pkgs%2Flibhtml-calendarmonth-perl.git;a=blobdiff_plain;f=1.25%2Flib%2FHTML%2FCalendarMonth%2FDateTool%2FDateCalc.pm;fp=1.25%2Flib%2FHTML%2FCalendarMonth%2FDateTool%2FDateCalc.pm;h=38cbcbb3869b7bcacb585f0e90081ffbe49ce3c2;hp=0000000000000000000000000000000000000000;hb=1a48ee7ffa0db08c3c5af68b365ee274acbd485d;hpb=2a7fc55a2e563096c7348a2f6272a16830561513 diff --git a/1.25/lib/HTML/CalendarMonth/DateTool/DateCalc.pm b/1.25/lib/HTML/CalendarMonth/DateTool/DateCalc.pm new file mode 100644 index 0000000..38cbcbb --- /dev/null +++ b/1.25/lib/HTML/CalendarMonth/DateTool/DateCalc.pm @@ -0,0 +1,68 @@ +package HTML::CalendarMonth::DateTool::DateCalc; +BEGIN { + $HTML::CalendarMonth::DateTool::DateCalc::VERSION = '1.25'; +} + +# Interface to Date::Calc + +use strict; +use warnings; +use Carp; + +use base qw( HTML::CalendarMonth::DateTool ); + +use Date::Calc qw( + Days_in_Month + Day_of_Week + Add_Delta_Days + Weeks_in_Year + Week_of_Year + Week_Number + Mktime +); + +sub dow1st_and_lastday { + my($self, $month, $year) = @_; + $month ||= $self->month; + $year ||= $self->year; + ($self->dow(1), Days_in_Month($year, $month)); +} + +sub day_epoch { + my($self, $day, $month, $year) = @_; + $month ||= $self->month; + $year ||= $self->year; + Mktime($year, $month, $day, 0, 0, 0); +} + +sub dow { + my($self, $day, $month, $year) = @_; + $day || croak "day required.\n"; + $month ||= $self->month; + $year ||= $self->year; + # Date::Calc uses 1..7 as indicies in the week, starting with Monday. + # Convert to 0..6, starting with Sunday. + Day_of_Week($year, $month, $day) % 7; +} + +sub add_days { + my($self, $delta, $day, $month, $year) = @_; + defined $delta || croak "delta (in days) required.\n"; + $day || croak "day required.\n"; + $month ||= $self->month; + $year ||= $self->year; + my($y, $m, $d) = Add_Delta_Days($year, $month, $day, $delta); + ($d, $m, $y); +} + +sub week_of_year { + my($self, $day, $month, $year) = @_; + $day || croak "day required.\n"; + $month ||= $self->month; + $year ||= $self->year; + my $week; + ($week, $year) = Week_of_Year($year, $month, $day); + ($year, $week); +} + +1;