File Coverage

blib/lib/DateTime/Calendar/CopticEthiopic.pm
Criterion Covered Total %
statement 13 67 19.4
branch 0 30 0.0
condition 0 12 0.0
subroutine 4 18 22.2
pod 0 6 0.0
total 17 133 12.7


line stmt bran cond sub pod time code
1             package DateTime::Calendar::CopticEthiopic;
2 1     1   8 use base (DateTime);
  1         2  
  1         3360  
3              
4             BEGIN
5             {
6 1     1   194 require 5.000;
7              
8 1     1   330438 use strict;
  1         2  
  1         44  
9 1         122 use vars qw(
10             $VERSION
11              
12             $true
13             $false
14              
15             @GregorianDaysPerMonth
16              
17             $n
18 1     1   5 );
  1         2  
19              
20 1         4 $VERSION = "0.13";
21              
22 1         2 ($false,$true) = (0,1);
23              
24 1         1310 @GregorianDaysPerMonth = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
25             }
26              
27              
28             #
29             #
30             # Calender System Conversion Methods Below Here:
31             #
32             #
33             sub _AbsoluteToEthiopic
34             {
35 0     0     my ( $self, $absolute ) = @_;
36              
37 0           my $year = quotient ( 4 * ( $absolute - $self->epoch ) + 1463, 1461 );
38 0           my $month = 1 + quotient ( $absolute - $self->_EthiopicToAbsolute ( 1, 1, $year ), 30 );
39 0           my $day = ( $absolute - $self->_EthiopicToAbsolute ( 1, $month, $year ) + 1 );
40              
41 0           ( $day, $month, $year );
42             }
43              
44              
45             sub fromGregorian
46             {
47 0     0 0   my $self = shift;
48              
49 0 0         die ( "Bogus Ethiopic Date!!" ) if ( $self->_isBogusGregorianDate ( @_ ) );
50              
51 0           $self->_AbsoluteToEthiopic ( $self->_GregorianToAbsolute ( @_ ) );
52             }
53              
54              
55             sub gregorian
56             {
57 0     0 0   my $self = shift;
58              
59 0           $self->_AbsoluteToGregorian ( $self->_EthiopicToAbsolute ( @_ ) );
60             }
61              
62              
63             sub _isBogusEthiopicDate
64             {
65 0     0     my $self = shift;
66              
67 0 0         my($day, $month, $year) = (@_) ? @_ : ($self->day, $self->month, $self->year);
68              
69 0 0 0       ( !( 1 <= $day && $day <= 30 )
70             || !( 1 <= $month && $month <= 13 )
71             || ( $month == 13 && $day > 6 )
72             || ( $month == 13 && $day == 6 && !$self->isLeapYear )
73             )
74             ?
75             $true : $false;
76              
77             }
78              
79              
80             sub _isBogusGregorianDate
81             {
82 0     0     my $self = shift;
83              
84 0 0         my($day, $month, $year) = (@_) ? @_ : ($self->day, $self->month, $self->year);
85              
86 0 0 0       ( !( 1 <= $month && $month <= 12 )
87             || !( 1 <= $day && $day <= $GregorianDaysPerMonth[$month-1] )
88             || ( $day == 29 && $month == 2 && !$self->_isGregorianLeapYear($year) )
89             )
90             ?
91             $true : $false;
92              
93             }
94              
95              
96             sub _EthiopicToAbsolute
97             {
98 0     0     my $self = shift;
99 0 0         my ( $date, $month, $year ) = ( @_ ) ? @_ : ($self->day,$self->month,$self->year);
100              
101 0           ( $self->epoch - 1 + 365 * ( $year - 1 ) + quotient ( $year, 4 ) + 30 * ( $month - 1 ) + $date );
102             }
103              
104              
105             sub _GregorianYear
106             {
107 0     0     my ( $a ) = @_;
108              
109 0           my $b = $a - 1;
110 0           my $c = quotient ( $b, 146097 );
111 0           my $d = mod ( $b, 146097 );
112 0           my $e = quotient ( $d, 36524 );
113 0           my $f = mod ( $d, 36524 );
114 0           my $g = quotient ( $f, 1461 );
115 0           my $h = mod ( $f, 1461 );
116 0           my $i = quotient ( $h, 365 );
117 0           my $j = ( 400 * $c ) + ( 100 * $e ) + ( 4 * $g ) + $i;
118              
119 0 0 0       ( ( $e == 4 ) || ( $i == 4 ) )
120             ? $j
121             : ( $j + 1 )
122             ;
123             }
124              
125              
126             sub _AbsoluteToGregorian
127             {
128 0     0     my ( $self, $absolute ) = @_;
129              
130 0           my $year = _GregorianYear ( $absolute );
131              
132 0           my $priorDays = ( $absolute - $self->_GregorianToAbsolute ( 1, 1, $year ) );
133              
134 0 0         my $correction
    0          
135             = ( $absolute < $self->_GregorianToAbsolute ( 1, 3, $year ) )
136             ? 0
137             : ( $self->_isGregorianLeapYear ( $year ) )
138             ? 1
139             : 2
140             ;
141              
142 0           my $month = quotient ( ( ( 12 * ( $priorDays + $correction ) + 373 ) / 367 ), 1 );
143 0           my $day = $absolute - $self->_GregorianToAbsolute ( 1, $month, $year ) + 1;
144              
145 0           ( $day, $month, $year );
146             }
147              
148              
149             sub _GregorianToAbsolute
150             {
151 0     0     my $self = shift;
152 0 0         my ( $date, $month, $year ) = ( @_ ) ? @_ : ($self->day,$self->month,$self->year);
153              
154 0 0         my $correction
    0          
155             = ( $month <= 2 )
156             ? 0
157             : ( $self->_isGregorianLeapYear ( $year ) )
158             ? -1
159             : -2
160             ;
161              
162 0           my $absolute =(
163             365 * ( $year - 1 )
164             + quotient ( $year - 1, 4 )
165             - quotient ( $year - 1, 100 )
166             + quotient ( $year - 1, 400 )
167             + ( 367 * $month - 362 ) / 12
168             + $correction + $date
169             );
170              
171 0           quotient ( $absolute, 1 );
172             }
173              
174              
175             sub _isGregorianLeapYear
176             {
177 0     0     shift;
178              
179             (
180 0 0 0       ( ( $_[0] % 4 ) != 0 )
181             || ( ( $_[0] % 400 ) == 100 )
182             || ( ( $_[0] % 400 ) == 200 )
183             || ( ( $_[0] % 400 ) == 300 )
184             )
185             ? 0
186             : 1
187             ;
188             }
189              
190              
191             #
192             # argument is an ethiopic year
193             #
194             sub isLeapYear
195             {
196 0     0 0   my $self = shift;
197 0 0         my ( $year ) = ( @_ ) ? shift : $self->year;
198              
199 0 0         ( ( $year + 1 ) % 4 ) ? 0 : 1 ;
200             }
201              
202              
203             sub quotient
204             {
205 0     0 0   $_ = $_[0] / $_[1];
206              
207 0           s/\.(.*)//;
208              
209 0           $_;
210             }
211              
212              
213             sub mod
214             {
215 0     0 0   ( $_[0] - $_[1] * quotient ( $_[0], $_[1] ) );
216             }
217              
218              
219             sub toGregorian
220             {
221 0     0 0   my $self = shift;
222              
223 0           my ($day,$month,$year) = $self->gregorian;
224              
225 0           new DateTime ( day => $day, month => $month, year => $year );
226             }
227              
228              
229             #########################################################
230             # Do not change this, Do not put anything below this.
231             # File must return "true" value at termination
232             1;
233             ##########################################################
234              
235             __END__