| 1 | package HTML::CalendarMonth::DateTool::Cal; | ||
| 2 | { | ||
| 3 | $HTML::CalendarMonth::DateTool::Cal::VERSION = '1.26'; | ||
| 4 | } | ||
| 5 | |||
| 6 | # Interface to unix 'cal' command | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | use Carp; | ||
| 11 | |||
| 12 | use base qw( HTML::CalendarMonth::DateTool ); | ||
| 13 | |||
| 14 | sub dow1st_and_lastday { | ||
| 15 | my($self, $month, $year) = @_; | ||
| 16 | $month ||= $self->month; | ||
| 17 | $year ||= $self->year; | ||
| 18 | my $cmd = $self->_cal_cmd or croak "cal command not found\n"; | ||
| 19 | |||
| 20 | my @cal = grep(!/^\s*$/,`$cmd $month $year`); | ||
| 21 | chomp @cal; | ||
| 22 | my @days = grep(/\d+/,split(/\s+/,$cal[2])); | ||
| 23 | my $dow1st = 6 - $#days; | ||
| 24 | my($lastday) = $cal[$#cal] =~ /(\d+)\s*$/; | ||
| 25 | # With dow1st and lastday, one builds a calendar sequentially. | ||
| 26 | # Historically, in particular Sep 1752, days have been skipped. Here's | ||
| 27 | # the chance to catch that. | ||
| 28 | $self->_skips(undef); | ||
| 29 | if ($month == 9 && $year == 1752) { | ||
| 30 | my %skips; | ||
| 31 | grep(++$skips{$_}, 3 .. 13); | ||
| 32 | $self->_skips(\%skips); | ||
| 33 | } | ||
| 34 | ($dow1st, $lastday); | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; |