]> git.donarmstrong.com Git - deb_pkgs/libhtml-calendarmonth-perl.git/blob - 1.16/lib/HTML/CalendarMonth/DateTool/DateCalc.pm
[svn-inject] Tagging upstream source version of libhtml-calendarmonth-perl
[deb_pkgs/libhtml-calendarmonth-perl.git] / 1.16 / lib / HTML / CalendarMonth / DateTool / DateCalc.pm
1 package HTML::CalendarMonth::DateTool::DateCalc;
2
3 # Interface to Date::Calc
4
5 use strict;
6 use Carp;
7
8 use vars qw(@ISA $VERSION);
9
10 @ISA = qw(HTML::CalendarMonth::DateTool);
11
12 $VERSION = '0.01';
13
14 use Date::Calc qw(Days_in_Month Day_of_Week Add_Delta_Days
15                   Weeks_in_Year Week_of_Year Week_Number Mktime
16                  );
17
18 sub dow1st_and_lastday {
19   my($self, $month, $year) = @_;
20   $month ||= $self->month;
21   $year  ||= $self->year;
22   my $lastday = Days_in_Month($year, $month);
23   # Date::Calc uses 1..7 as indicies in the week, starting with Monday.
24   # Internally, we use 0..6, starting with Sunday. These turn out to be
25   # identical except for Sunday.
26   my $dow1st = $self->dow(1);
27   $dow1st = 0 if $dow1st == 7;
28   ($dow1st, $lastday);
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   Day_of_Week($year, $month, $day);
44 }
45
46 sub add_days {
47   my($self, $delta, $day, $month, $year) = @_;
48   $delta || croak "Delta (in days) required.\n";
49   $day   || croak "Day required.\n";
50   $month ||= $self->month;
51   $year  ||= $self->year;
52   my($y, $m, $d) = Add_Delta_Days($year, $month, $day, $delta);
53   ($d, $m, $y);
54 }
55
56 sub week_of_year {
57   my($self, $day, $month, $year) = @_;
58   $day || croak "Day required.\n";
59   $month ||= $self->month;
60   $year  ||= $self->year;
61   my($week, $year) = Week_of_Year($year, $month, $day);
62   ($year, $week);
63 }
64
65 1;