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   924 use strict;
  4         5  
  4         91  
9 4     4   12 use warnings;
  4         4  
  4         89  
10 4     4   11 use Carp;
  4         3  
  4         206  
11              
12 4     4   14 use base qw( HTML::CalendarMonth::DateTool );
  4         3  
  4         275  
13              
14 4     4   14 use Time::Local;
  4         3  
  4         542  
15              
16             sub dow1st_and_lastday {
17 921     921 1 1020 my($self, $month, $year) = @_;
18 921   33     2849 $month ||= $self->month;
19 921   33     2249 $year ||= $self->year;
20             # map month to 0-12
21 921         1158 --$month;
22             # years since 1900...hooh-rah for POSIX...
23 921         852 $year -= 1900;
24 921         842 my $nmonth = $month + 1;
25 921         696 my $nyear = $year;
26 921 100       1399 if ($nmonth > 11) {
27             # Happy new year
28 78         77 $nmonth = 0;
29 78         74 ++$nyear;
30             }
31             # Leave dow of 1st in 0-based format
32 921         1969 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         21069 my $lastday = (gmtime(Time::Local::timegm(0,0,0,1,$nmonth,$nyear)
35             - 60*60*24))[3];
36 921         15071 ($dow1st, $lastday);
37             }
38              
39             1;