App/Chart/Timebase/Months.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 44 CC 1 SCAR 6.9
CC
1
Cov
0%
new_from_ymd
2.0
to_ymd
2.0
from_ymd_floor
2.0
CRAP 2.0
1 # Copyright 2007, 2008, 2009 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17  
18 package App::Chart::Timebase::Months;
19 use strict;
20 use warnings;
21 use Date::Calc;
22 use Locale::TextDomain ('App-Chart');
23  
24 use App::Chart;
25 use base 'App::Chart::Timebase';
26  
27 sub new_from_ymd {
28 my ($class, $year, $month, $day) = @_;
29 return $class->SUPER::new
30 (base => ymd_to_mdate ($year, $month, $day));
31 }
32  
33 sub to_ymd {
34 my ($self, $t) = @_;
35 return Date::Calc::Add_Delta_YM (1970,1,1, 0, $t + $self->{'base'});
36 }
37  
38 sub from_ymd_floor {
39 my ($self, $year, $month, $day) = @_;
40 return ymd_to_mdate ($year, $month, $day) - $self->{'base'};
41 }
42 *from_ymd_ceil = \&from_ymd_floor;
43  
44 sub adjective { return __('Monthly'); }
45  
46 #------------------------------------------------------------------------------
47  
48 sub ymd_to_mdate {
49 my ($year, $month, $day) = @_;
50 return ($year - 1970) * 12 + ($month - 1);
51 }
52  
53  
54 1;