File Coverage

blib/lib/Calendar/Julian.pm
Criterion Covered Total %
statement 17 38 44.7
branch 0 6 0.0
condition 0 3 0.0
subroutine 6 12 50.0
pod 4 6 66.6
total 27 65 41.5


line stmt bran cond sub pod time code
1             package Calendar::Julian;
2              
3             $Calendar::Julian::VERSION = '0.02';
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.02
13              
14             =cut
15              
16 1     1   85593 use 5.006;
  1         5  
17 1     1   705 use Data::Dumper;
  1         7412  
  1         88  
18              
19 1     1   616 use Date::Julian::Simple;
  1         147350  
  1         31  
20 1     1   8 use Moo;
  1         2  
  1         4  
21 1     1   267 use namespace::clean;
  1         8  
  1         4  
22 1     1   226 use overload q{""} => 'as_string', fallback => 1;
  1         1  
  1         8  
23              
24             has year => (is => 'rw', predicate => 1);
25             has month => (is => 'rw', predicate => 1);
26             has date => (is => 'ro', default => sub { Date::Julian::Simple->new });
27             with 'Calendar::Plugin::Renderer';
28              
29             sub BUILD {
30 0     0 0   my ($self) = @_;
31              
32 0 0         $self->date->validate_year($self->year) if $self->has_year;
33 0 0         $self->date->validate_month($self->month) if $self->has_month;
34              
35 0 0 0       unless ($self->has_year && $self->has_month) {
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 provides command line tool C to display the
76             supported calendars on the terminal. Support for C is provided
77             by L 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     0 1   my ($self) = @_;
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     0 1   my ($self, $julian_day) = @_;
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     0 1   my ($self, $month, $year) = @_;
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     0 1   my ($self, $month, $year) = @_;
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     0 0   my ($self) = @_;
204              
205 0           return $self->as_text($self->month, $self->year);
206             }
207              
208             =head1 AUTHOR
209              
210             Mohammad S Anwar, C<< >>
211              
212             =head1 REPOSITORY
213              
214             L
215              
216             =head1 SEE ALSO
217              
218             =over 4
219              
220             =item L
221              
222             =item L
223              
224             =item L
225              
226             =item L
227              
228             =item L
229              
230             =item L
231              
232             =back
233              
234             =head1 BUGS
235              
236             Please report any bugs / feature requests to C
237             or through the web interface at L.
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
254              
255             =item * AnnoCPAN: Annotated CPAN documentation
256              
257             L
258              
259             =item * CPAN Ratings
260              
261             L
262              
263             =item * Search CPAN
264              
265             L
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
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             1; # End of Calendar::Julian