blib/lib/DateTime/Calendar/Julian.pm

filter: Statementstmt 100% 62 / 62 Branchbran 100% 12 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 5 / 5 totaltotal 100% 97 / 97 CC 8 SCAR 8.3
CC
8
Cov
100%
_rd2ymd
5.0
_floor
2.0
gregorian_deviation
2.0
CRAP 2.3
↑ Summary
1 package DateTime::Calendar::Julian;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 $VERSION = '0.108';
9  
10 4 ▶use DateTime 0.08;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 @ISA = 'DateTime';
12  
13 282 ▶sub _floor {
Subroutine _floor: called CC=2 SCAR=6.9
14 282 my $x = shift;
15 282 my $ix = int $x;
16 282 ▶ if ($ix <= $x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix <= $x) { } 231 51 282
17 231 return $ix;
18 } else {
19 51 return $ix - 1;
20 }
21 }
22  
23 4 my @start_of_month = (0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337);
24  
25 # Julian dates are formatted in exactly the same way as Gregorian dates,
26 # so we use most of the DateTime methods.
27  
28 # This is the difference between Julian and Gregorian calendar:
29 166 ▶sub _is_leap_year {
Subroutine _is_leap_year: called CC=1 SCAR=0.0
30 166 my (undef, $year) = @_; # Invocant unused
31  
32 166 return ($year % 4 == 0);
33 }
34  
35 # Algorithms from http://home.capecod.net/~pbaum/date/date0.htm
36 64 ▶sub _ymd2rd { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _ymd2rd: called CC=1 SCAR=0.0
37 64 my (undef, $y, $m, $d) = @_; # Invocant unused
38  
39 64 my $adj = _floor( ($m-3)/12 );
40 64 $m -= 12 * $adj;
41 64 $y += $adj;
42  
43 64 my $rd = $d + $start_of_month[$m-3] + 365*$y + _floor($y/4) - 308;
44 64 return $rd;
45 }
46  
47 {
48 4 my @QuarterStart = my @LeapYearQuarterStart = ( 0, 90, 181, 273 );
49 4 $LeapYearQuarterStart[$_] += 1 for 1 .. 3;
50  
51 71 ▶ sub _rd2ymd { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _rd2ymd: called CC=5 SCAR=16.1
52 71 my ($class, $rd, $extra) = @_;
53  
54 71 my $z = $rd + 308;
55 71 my $y = _floor(($z*100-25)/36525);
56 71 my $c = $z - _floor(365.25*$y);
57 71 my $m = int((5*$c + 456)/153);
58 71 my $d = $c - $start_of_month[$m-3];
59 71 ▶ if ($m > 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m > 12) 34 37 71
60 34 $m -= 12;
61 34 $y++;
62 }
63  
64 71 ▶ if ($extra) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra) 62 9 71
65 # day_of_week, day_of_year
66 62 ▶ my $doy = ($c + 31 + 28 - 1)%365 + 1 +
Condition100%3/3
$class->_is_leap_year($y) && $m > 2
!ll&&!rl&&r
351710
MC/DC100%2/2
$class->_is_leap_year($y) && $m > 2
$class->_is_leap_year($y) $m > 2
Truth table100%3/3
A && B
A= $class->_is_leap_year($y)B= $m > 2
ABresult
0X0
100
111
67 ($class->_is_leap_year($y) && $m > 2);
68 62 my $dow = (($rd + 6)%7) + 1;
69  
70 # quarter -- see DateTime::PP->rd2ymd()
71 62 my $quarter = int( ( 1 / 3.1 ) * $m ) + 1;
72  
73 62 ▶ my $doq = $doy - ( $class->_is_leap_year( $y ) ?
Branch: 1 branch
BranchTrueFalseTotal
$class->_is_leap_year($y) ? : 27 35 62
74 $LeapYearQuarterStart[ $quarter - 1 ] :
75 $QuarterStart[ $quarter - 1 ] );
76  
77 62 return $y, $m, $d, $dow, $doy, $quarter, $doq;
78 }
79 9 return $y, $m, $d;
80 }
81 }
82  
83 4 ▶sub calendar_name {
Subroutine calendar_name: called CC=1 SCAR=0.0
Pod documented
84 1 return 'Julian';
85 }
86  
87 1 ▶sub epoch {
Subroutine epoch: called CC=1 SCAR=0.0
Pod documented
88 1 my $self = shift;
89  
90 1 my $greg = DateTime->from_object( object => $self );
91 1 return $greg->epoch;
92 }
93  
94 1 ▶sub from_epoch {
Subroutine from_epoch: called CC=1 SCAR=0.0
Pod documented
95 1 my $class = shift;
96  
97 1 my $greg = DateTime->from_epoch( @_ );
98 1 return $class->from_object( object => $greg );
99 }
100  
101 6 ▶sub gregorian_deviation {
Subroutine gregorian_deviation: called CC=2 SCAR=6.9
Pod documented
102 6 my $self = shift;
103  
104 6 my $year = $self->{local_c}{year};
105 6 ▶ $year-- if $self->{local_c}{month} <= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"local_c"}{"month"} <= 2 4 2 6
106  
107 6 return _floor($year/100)-_floor($year/400)-2;
108 }
109  
110 # NOTE: Do NOT just default the separator to 'J' and delegate to SUPER.
111 # This will not work before DateTime 1.43 because before that the
112 # datetime() method did not have an argument.
113 12 ▶sub datetime {
Subroutine datetime: called CC=2 SCAR=6.9
Pod documented
114 12 my ( $self, $sep ) = @_;
115 12 ▶ $sep = 'J' unless defined $sep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sep 6 6 12
116 12 return join $sep, $self->ymd( '-' ), $self->hms( ':' );
117 }
118  
119 4 1;
120  
121 __END__
↑ Summary