blib/lib/Calendar/Julian.pm

filter: Statementstmt 52.1% 24 / 46 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 46.1% 6 / 13 Podpod 66.6% 4 / 6 totaltotal 44.7% 34 / 76 CC 5 SCAR 22.9
CC
5
Cov
44%
BUILD
30.0
current
2.0
from_julian
2.0
CRAP 9.8
↑ Summary
1 package Calendar::Julian;
2  
3 4 $Calendar::Julian::VERSION = '0.10';
4 4 $Calendar::Julian::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Calendar::Julian - Interface to Julian Calendar.
9  
10 =head1 VERSION
11  
12 Version 0.10
13  
14 =cut
15  
16 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 ▶use Date::Julian::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use overload q{""} => 'as_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 4 has year => (is => 'rw', predicate => 1);
25 4 has month => (is => 'rw', predicate => 1);
26 0 ▶has date => (is => 'ro', default => sub { Date::Julian::Simple->new });
Subroutine __ANON__: not called CC=1 SCAR=1.2
27 4 with 'Calendar::Plugin::Renderer';
28  
29 sub BUILD {
30 0 ▶ my ($self) = @_;
Subroutine BUILD: not called CC=5 SCAR=34.0
Pod undocumented
31  
32 0 ▶ $self->date->validate_year($self->year) if $self->has_year;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_year 0 0 0
33 0 ▶ $self->date->validate_month($self->month) if $self->has_month;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_month 0 0 0
34  
35 0 ▶ unless ($self->has_year && $self->has_month) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_year and $self->has_month) 0 0 0
Condition0%0/3
$self->has_year and $self->has_month
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_year and $self->has_month
$self->has_year $self->has_month
Truth table0%0/3
A and B
A= $self->has_yearB= $self->has_month
ABresult
0X0
100
111
36 0 $self->year($self->date->year);
37 0 $self->month($self->date->month);
38 }
39 }
40  
41 =head1 DESCRIPTION
42  
43 The Julian calendar was proclaimed by Julius Cesar in 46 B.C. and underwent
44 several modifications before reaching its final form in 8 C.E.The Julian calendar
45 differs from the Gregorian only in the determination of leap years, lacking the
46 correction for years divisible by 100 and 400 in the Gregorian calendar. In the
47 Julian calendar, any positive year is a leap year if divisible by 4. (Negative
48 years are leap years if the absolute value divided by 4 yields a remainder of 1.)
49 Days are considered to begin at midnight.
50  
51 In the Julian calendar the average year has a length of 365.25 days. compared to
52 the actual solar tropical year of 365.24219878 days.The calendar thus accumulates
53 one day of error with respect to the solar year every 128 years. Being a purely
54 solar calendar, no attempt is made to synchronise the start of months to the
55 phases of the Moon.
56  
57 +-----------------------------------------------------------------------------------+
58 | July [2017 BE] |
59 +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
60 | Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday |
61 +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
62 | | 1 | 2 |
63 +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
64 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
65 +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
66 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
67 +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
68 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
69 +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
70 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
71 +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
72 | 31 | |
73 +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
74  
75 The package L<App::calendr> provides command line tool C<calendr> to display the
76 supported calendars on the terminal. Support for C<Julian Calendar> is provided
77 by L<App::calendr> v0.17 or above.
78  
79 =head1 SYNOPSIS
80  
81 use strict; use warnings;
82 use Calendar::Julian;
83  
84 # prints current julian month calendar.
85 print Calendar::Julian->new, "\n";
86 print Calendar::Julian->new->current, "\n";
87  
88 # prints julian month calendar in which the given julian day falls in.
89 print Calendar::Julian->new->from_julian(2457102.5), "\n";
90  
91 # prints current month julian calendar in SVG format.
92 print Calendar::Julian->new->as_svg;
93  
94 # prints current month julian calendar in text format.
95 print Calendar::Julian->new->as_text;
96  
97 =head1 JULIAN MONTHS
98  
99 +--------+------------------------------------------------------------------+
100 | Number | Name |
101 +--------+------------------------------------------------------------------+
102 | 1 | January |
103 | 2 | February |
104 | 3 | March |
105 | 4 | April |
106 | 5 | May |
107 | 6 | June |
108 | 7 | July |
109 | 8 | August |
110 | 9 | September |
111 | 10 | October |
112 | 11 | November |
113 | 12 | December |
114 +--------+------------------------------------------------------------------+
115  
116 =head1 JULIAN DAYS
117  
118 +---------------------------------------------------------------------------+
119 | English Name |
120 +---------------------------------------------------------------------------+
121 | Sunday |
122 | Monday |
123 | Tuesday |
124 | Wednesday |
125 | Thursday |
126 | Friday |
127 | Saturday |
128 +---------------------------------------------------------------------------+
129  
130 =head1 METHODS
131  
132 =head2 current()
133  
134 Returns current month of the Julian calendar.
135  
136 =cut
137  
138 sub current {
139 0 ▶ my ($self) = @_;
Subroutine current: not called CC=1 SCAR=6.9
Pod documented
140  
141 0 return $self->as_text($self->date->month, $self->date->year);
142 }
143  
144 =head2 from_julian($julian_day)
145  
146 Returns Julian month calendar in which the given C<$julian_day> falls in.
147  
148 =cut
149  
150 sub from_julian {
151 0 ▶ my ($self, $julian_day) = @_;
Subroutine from_julian: not called CC=1 SCAR=6.9
Pod documented
152  
153 0 my $date = $self->date->from_julian($julian_day);
154 0 return $self->as_text($date->month, $date->year);
155 }
156  
157 =head2 as_svg($month, $year)
158  
159 Returns calendar for the given C<$month> and C<$year> rendered in SVG format. If
160 C<$month> and C<$year> missing, it would return current calendar month.
161  
162 =cut
163  
164 sub as_svg {
165 0 ▶ my ($self, $month, $year) = @_;
Subroutine as_svg: not called CC=1 SCAR=6.9
Pod documented
166  
167 0 ($month, $year) = $self->validate_params($month, $year);
168 0 my $date = Date::Julian::Simple->new({ year => $year, month => $month, day => 1 });
169  
170 0 return $self->svg_calendar(
171 {
172 start_index => $date->day_of_week,
173 month_name => $date->months->[$month],
174 days => $date->days_in_month_year($month, $year),
175 year => $year
176 });
177 }
178  
179 =head2 as_text($month, $year)
180  
181 Returns color coded Julian calendar for the given C<$month> and C<$year>. If
182 C<$month> and C<$year> missing, it would return current calendar month.
183  
184 =cut
185  
186 sub as_text {
187 0 ▶ my ($self, $month, $year) = @_;
Subroutine as_text: not called CC=1 SCAR=6.9
Pod documented
188  
189 0 ($month, $year) = $self->validate_params($month, $year);
190 0 my $date = Date::Julian::Simple->new({ year => $year, month => $month, day => 1 });
191  
192 0 return $self->text_calendar(
193 {
194 start_index => $date->day_of_week,
195 month_name => $date->get_month_name,
196 days => $date->days_in_month_year($month, $year),
197 day_names => $date->days,
198 year => $year
199 });
200 }
201  
202 sub as_string {
203 0 ▶ my ($self) = @_;
Subroutine as_string: not called CC=1 SCAR=6.9
Pod undocumented
204  
205 0 return $self->as_text($self->month, $self->year);
206 }
207  
208 =head1 AUTHOR
209  
210 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
211  
212 =head1 REPOSITORY
213  
214 L<https://github.com/manwar/Calendar-Julian>
215  
216 =head1 SEE ALSO
217  
218 =over 4
219  
220 =item L<Calendar::Bahai>
221  
222 =item L<Calendar::Hebrew>
223  
224 =item L<Calendar::Hijri>
225  
226 =item L<Calendar::Gregorian>
227  
228 =item L<Calendar::Persian>
229  
230 =item L<Calendar::Saka>
231  
232 =back
233  
234 =head1 BUGS
235  
236 Please report any bugs / feature requests to C<bug-calendar-julian at rt.cpan.org>
237 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Calendar-Julian>.
238 I will be notified, and then you'll automatically be notified of progress on your
239 bug as I make changes.
240  
241 =head1 SUPPORT
242  
243 You can find documentation for this module with the perldoc command.
244  
245 perldoc Calendar::Julian
246  
247 You can also look for information at:
248  
249 =over 4
250  
251 =item * RT: CPAN's request tracker
252  
253 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Calendar-Julian>
254  
255 =item * AnnoCPAN: Annotated CPAN documentation
256  
257 L<http://annocpan.org/dist/Calendar-Julian>
258  
259 =item * CPAN Ratings
260  
261 L<http://cpanratings.perl.org/d/Calendar-Julian>
262  
263 =item * Search CPAN
264  
265 L<http://search.cpan.org/dist/Calendar-Julian/>
266  
267 =back
268  
269 =head1 LICENSE AND COPYRIGHT
270  
271 Copyright (C) 2017 Mohammad S Anwar.
272  
273 This program is free software; you can redistribute it and / or modify it under
274 the terms of the the Artistic License (2.0). You may obtain a copy of the full
275 license at:
276  
277 L<http://www.perlfoundation.org/artistic_license_2_0>
278  
279 Any use, modification, and distribution of the Standard or Modified Versions is
280 governed by this Artistic License.By using, modifying or distributing the Package,
281 you accept this license. Do not use, modify, or distribute the Package, if you do
282 not accept this license.
283  
284 If your Modified Version has been derived from a Modified Version made by someone
285 other than you,you are nevertheless required to ensure that your Modified Version
286 complies with the requirements of this license.
287  
288 This license does not grant you the right to use any trademark, service mark,
289 tradename, or logo of the Copyright Holder.
290  
291 This license includes the non-exclusive, worldwide, free-of-charge patent license
292 to make, have made, use, offer to sell, sell, import and otherwise transfer the
293 Package with respect to any patent claims licensable by the Copyright Holder that
294 are necessarily infringed by the Package. If you institute patent litigation
295 (including a cross-claim or counterclaim) against any party alleging that the
296 Package constitutes direct or contributory patent infringement,then this Artistic
297 License to you shall terminate on the date that such litigation is filed.
298  
299 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
300 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
301 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
302 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
303 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
304 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
305 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
306  
307 =cut
308  
309 4 1; # End of Calendar::Julian
↑ Summary