File Coverage

blib/lib/HTML/CalendarMonth/DateTool/TimeLocal.pm
Criterion Covered Total %
statement 28 28 100.0
branch 2 2 100.0
condition 2 6 33.3
subroutine 6 6 100.0
pod 1 1 100.0
total 39 43 90.7


line stmt bran cond sub pod time code
1             package HTML::CalendarMonth::DateTool::TimeLocal;
2             {
3             $HTML::CalendarMonth::DateTool::TimeLocal::VERSION = '1.26';
4             }
5              
6             # Interface to Time::Local
7              
8 4     4   1085 use strict;
  4         7  
  4         109  
9 4     4   22 use warnings;
  4         6  
  4         123  
10 4     4   19 use Carp;
  4         7  
  4         236  
11              
12 4     4   20 use base qw( HTML::CalendarMonth::DateTool );
  4         7  
  4         329  
13              
14 4     4   18 use Time::Local;
  4         8  
  4         782  
15              
16             sub dow1st_and_lastday {
17 921     921 1 1604 my($self, $month, $year) = @_;
18 921   33     3693 $month ||= $self->month;
19 921   33     3576 $year ||= $self->year;
20             # map month to 0-12
21 921         1674 --$month;
22             # years since 1900...hooh-rah for POSIX...
23 921         1417 $year -= 1900;
24 921         1304 my $nmonth = $month + 1;
25 921         1204 my $nyear = $year;
26 921 100       2145 if ($nmonth > 11) {
27             # Happy new year
28 78         99 $nmonth = 0;
29 78         124 ++$nyear;
30             }
31             # Leave dow of 1st in 0-based format
32 921         3272 my $dow1st = (gmtime(Time::Local::timegm(0,0,0,1,$month,$year)))[6];
33             # Last day is one day prior to 1st of month after
34 921         28640 my $lastday = (gmtime(Time::Local::timegm(0,0,0,1,$nmonth,$nyear)
35             - 60*60*24))[3];
36 921         25826 ($dow1st, $lastday);
37             }
38              
39             1;