| 1 | package HTML::CalendarMonth::DateTool::DateCalc; | ||
| 2 | { | ||
| 3 | $HTML::CalendarMonth::DateTool::DateCalc::VERSION = '1.26'; | ||
| 4 | } | ||
| 5 | |||
| 6 | # Interface to Date::Calc | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | use Carp; | ||
| 11 | |||
| 12 | use base qw( HTML::CalendarMonth::DateTool ); | ||
| 13 | |||
| 14 | use Date::Calc qw( | ||
| 15 | Days_in_Month | ||
| 16 | Day_of_Week | ||
| 17 | Add_Delta_Days | ||
| 18 | Weeks_in_Year | ||
| 19 | Week_of_Year | ||
| 20 | Week_Number | ||
| 21 | Mktime | ||
| 22 | ); | ||
| 23 | |||
| 24 | sub dow1st_and_lastday { | ||
| 25 | my($self, $month, $year) = @_; | ||
| 26 | $month ||= $self->month; | ||
| 27 | $year ||= $self->year; | ||
| 28 | ($self->dow(1), Days_in_Month($year, $month)); | ||
| 29 | } | ||
| 30 | |||
| 31 | sub day_epoch { | ||
| 32 | my($self, $day, $month, $year) = @_; | ||
| 33 | $month ||= $self->month; | ||
| 34 | $year ||= $self->year; | ||
| 35 | Mktime($year, $month, $day, 0, 0, 0); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub dow { | ||
| 39 | my($self, $day, $month, $year) = @_; | ||
| 40 | $day || croak "day required.\n"; | ||
| 41 | $month ||= $self->month; | ||
| 42 | $year ||= $self->year; | ||
| 43 | # Date::Calc uses 1..7 as indicies in the week, starting with Monday. | ||
| 44 | # Convert to 0..6, starting with Sunday. | ||
| 45 | Day_of_Week($year, $month, $day) % 7; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub add_days { | ||
| 49 | my($self, $delta, $day, $month, $year) = @_; | ||
| 50 | defined $delta || croak "delta (in days) required.\n"; | ||
| 51 | $day || croak "day required.\n"; | ||
| 52 | $month ||= $self->month; | ||
| 53 | $year ||= $self->year; | ||
| 54 | my($y, $m, $d) = Add_Delta_Days($year, $month, $day, $delta); | ||
| 55 | ($d, $m, $y); | ||
| 56 | } | ||
| 57 | |||
| 58 | sub week_of_year { | ||
| 59 | my($self, $day, $month, $year) = @_; | ||
| 60 | $day || croak "day required.\n"; | ||
| 61 | $month ||= $self->month; | ||
| 62 | $year ||= $self->year; | ||
| 63 | my $week; | ||
| 64 | ($week, $year) = Week_of_Year($year, $month, $day); | ||
| 65 | ($year, $week); | ||
| 66 | } | ||
| 67 | |||
| 68 | 1; |