File Coverage

blib/lib/Date/Decade.pm
Criterion Covered Total %
statement 12 49 24.4
branch 0 18 0.0
condition 0 9 0.0
subroutine 4 10 40.0
pod 0 5 0.0
total 16 91 17.5


line stmt bran cond sub pod time code
1             # Date::Decade.pm
2             #
3             # Copyright (c) 2001 Michael Diekmann . All rights
4             # reserved. This program is free software; you can redistribute it and/or
5             # modify it under the same terms as Perl itself.
6              
7             # Documentation could be found at the bottom or use (after install):
8             # > perldoc Date::Decade
9              
10             package Date::Decade;
11              
12             require 5.003_03;
13             require Exporter;
14              
15 1     1   848 use strict;
  1         3  
  1         42  
16 1     1   6 use Carp;
  1         2  
  1         113  
17 1         3372 use vars qw(@EXPORT_OK %EXPORT_TAGS @ISA $VERSION
18             @arr_Days_in_Decade
19 1     1   6 );
  1         5  
20              
21             #use Date::Pcalc 1.2 qw(
22             # leap_year
23             # check_date
24             # Day_of_Year
25             #);
26 1         766 use Date::Calc 4.3 qw(
27             leap_year
28             check_date
29             Day_of_Year
30 1     1   783 );
  1         110671  
31              
32             @ISA = qw(Exporter);
33              
34             # we export nothing by default :)
35             @EXPORT_OK = qw(
36             Days_in_Decade
37             Decade_of_Year
38             Decade_of_Month
39             );
40             %EXPORT_TAGS = (all => [@EXPORT_OK] );
41              
42             @arr_Days_in_Decade = (
43             [ 10,10,11 , 10,10,8 , 10,10,11 , 10,10,10 , 10,10,11 , 10,10,10 , 10,10,11 , 10,10,11 , 10,10,10 , 10,10,11 , 10,10,10 , 10,10,11 ],
44             [ 10,10,11 , 10,10,9 , 10,10,11 , 10,10,10 , 10,10,11 , 10,10,10 , 10,10,11 , 10,10,11 , 10,10,10 , 10,10,11 , 10,10,10 , 10,10,11 ]
45             );
46              
47             $VERSION = '0.33';
48              
49             #///////////////////////////////////////////////////////////////////////#
50             # #
51             #///////////////////////////////////////////////////////////////////////#
52              
53             sub Days_in_Decade {
54 0     0 0   my $year = shift;
55 0           my $decade = shift;
56              
57 0 0         if ($year > 0) {
58 0 0 0       if (($decade >= 1) && ($decade <= 36)) {
59 0           return $arr_Days_in_Decade[leap_year($year)][$decade-1];
60             }
61             else {
62 0           DATECALC_DECADE_ERROR("Days_in_Decade");
63             }
64             }
65             else {
66 0           DATECALC_YEAR_ERROR("Days_in_Decade");
67             }
68             }
69              
70             #///////////////////////////////////////////////////////////////////////#
71             # #
72             #///////////////////////////////////////////////////////////////////////#
73              
74             sub Decade_of_Year {
75 0     0 0   my $year = shift;
76 0           my $month = shift;
77 0           my $day = shift;
78              
79 0 0         if (check_date($year, $month, $day)) {
80 0           my $n_days = Day_of_Year($year,$month,$day);
81 0           my $decade = _round($n_days / 10);
82 0 0         if ($decade > 36) {
    0          
83 0           $decade = 36;
84             }
85             elsif ($decade == 0) {
86 0           $decade = 1;
87             }
88 0           return $decade;
89             }
90             else {
91 0           DATECALC_DATE_ERROR("Decade_of_Year");
92             }
93             }
94              
95             #///////////////////////////////////////////////////////////////////////#
96             # #
97             #///////////////////////////////////////////////////////////////////////#
98              
99             sub Decade_of_Month {
100 0     0 0   my $year = shift;
101 0           my $month = shift;
102 0           my $day = shift;
103              
104 0 0         if (check_date($year, $month, $day)) {
105 0           my $decade = ($day - ($day % 10)) / 10 + 1;
106 0 0         if ($decade >= 4) {
107 0           $decade = 3;
108             }
109 0           return $decade;
110             }
111             else {
112 0           DATECALC_DATE_ERROR("Decade_of_Month");
113             }
114             }
115              
116             #///////////////////////////////////////////////////////////////////////#
117             # #
118             #///////////////////////////////////////////////////////////////////////#
119              
120             sub _round {
121 0     0     $_ = shift;
122 0           my $x = int($_);
123 0 0 0       if (($_ >= 0) && (($_ - $x) >= 0.5)) {
    0 0        
124 0           $x++;
125             }
126             elsif (($_ < 0) && (($x - $_) >= 0.5)) {
127 0           $x--;
128             }
129 0           return $x;
130             }
131              
132             #///////////////////////////////////////////////////////////////////////#
133             # #
134             #///////////////////////////////////////////////////////////////////////#
135              
136             sub DATECALC_DECADE_ERROR {
137 0     0 0   my ($name) = @_;
138 0           croak("Date::Pcalc::${name}(): decade out of range");
139             }
140              
141             sub DATECALC_DATE_ERROR {
142 0     0 0   my ($name) = @_;
143 0           croak("Date::Pcalc::${name}(): not a valid date");
144             }
145              
146             1;
147              
148             __END__