X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=1.25%2Flib%2FHTML%2FCalendarMonth%2FDateTool%2FCal.pm;fp=1.25%2Flib%2FHTML%2FCalendarMonth%2FDateTool%2FCal.pm;h=2d63e006f77fadb7b886aaceb415440a5e00396e;hb=1a48ee7ffa0db08c3c5af68b365ee274acbd485d;hp=0000000000000000000000000000000000000000;hpb=2a7fc55a2e563096c7348a2f6272a16830561513;p=deb_pkgs%2Flibhtml-calendarmonth-perl.git diff --git a/1.25/lib/HTML/CalendarMonth/DateTool/Cal.pm b/1.25/lib/HTML/CalendarMonth/DateTool/Cal.pm new file mode 100644 index 0000000..2d63e00 --- /dev/null +++ b/1.25/lib/HTML/CalendarMonth/DateTool/Cal.pm @@ -0,0 +1,37 @@ +package HTML::CalendarMonth::DateTool::Cal; +BEGIN { + $HTML::CalendarMonth::DateTool::Cal::VERSION = '1.25'; +} + +# Interface to unix 'cal' command + +use strict; +use warnings; +use Carp; + +use base qw( HTML::CalendarMonth::DateTool ); + +sub dow1st_and_lastday { + my($self, $month, $year) = @_; + $month ||= $self->month; + $year ||= $self->year; + my $cmd = $self->_cal_cmd or croak "cal command not found\n"; + + my @cal = grep(!/^\s*$/,`$cmd $month $year`); + chomp @cal; + my @days = grep(/\d+/,split(/\s+/,$cal[2])); + my $dow1st = 6 - $#days; + my($lastday) = $cal[$#cal] =~ /(\d+)\s*$/; + # With dow1st and lastday, one builds a calendar sequentially. + # Historically, in particular Sep 1752, days have been skipped. Here's + # the chance to catch that. + $self->_skips(undef); + if ($month == 9 && $year == 1752) { + my %skips; + grep(++$skips{$_}, 3 .. 13); + $self->_skips(\%skips); + } + ($dow1st, $lastday); +} + +1;