]> git.donarmstrong.com Git - deb_pkgs/libhtml-calendarmonth-perl.git/blob - lib/HTML/CalendarMonth/DateTool/Cal.pm
6542a42017a0b218982498275a8a1ea25436e287
[deb_pkgs/libhtml-calendarmonth-perl.git] / lib / HTML / CalendarMonth / DateTool / Cal.pm
1 package HTML::CalendarMonth::DateTool::Cal;
2
3 # Interface to unix 'cal' command
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 Time::Local;
15
16 sub dow1st_and_lastday {
17   my($self, $month, $year) = @_;
18   $month ||= $self->month;
19   $year  ||= $self->year;
20   my $cmd = $self->cal_cmd or croak "cal command not found\n";
21
22   my @cal = grep(!/^\s*$/,`$cmd $month $year`);
23   chomp @cal;
24   my @days     = grep(/\d+/,split(/\s+/,$cal[2]));
25   my $dow1st   = 6 - $#days;
26   my($lastday) = $cal[$#cal] =~ /(\d+)\s*$/;
27   # With dow1st and lastday, one builds a calendar sequentially.
28   # Historically, in particular Sep 1752, days have been skipped. Here's
29   # the chance to catch that.
30   $self->skips(undef);
31   if ($month == 9 && $year == 1752) {
32     my %skips;
33     grep(++$skips{$_}, 3 .. 13);
34     $self->skips(\%skips);
35   }
36   ($dow1st, $lastday);
37 }
38
39 1;