File Coverage

blib/lib/Calendar/Hebrew.pm
Criterion Covered Total %
statement 17 46 36.9
branch 0 10 0.0
condition 0 3 0.0
subroutine 6 14 42.8
pod 5 8 62.5
total 28 81 34.5


line stmt bran cond sub pod time code
1             package Calendar::Hebrew;
2              
3             $Calendar::Hebrew::VERSION = '0.15';
4             $Calendar::Hebrew::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Calendar::Hebrew - Interface to Hebrew Calendar.
9              
10             =head1 VERSION
11              
12             Version 0.15
13              
14             =cut
15              
16 1     1   78997 use 5.006;
  1         4  
17 1     1   639 use Data::Dumper;
  1         6905  
  1         138  
18              
19 1     1   480 use Date::Hebrew::Simple;
  1         113293  
  1         32  
20 1     1   7 use Moo;
  1         2  
  1         3  
21 1     1   235 use namespace::autoclean;
  1         1  
  1         3  
22             with 'Calendar::Plugin::Renderer';
23              
24 1     1   60 use overload q{""} => 'as_string', fallback => 1;
  1         2  
  1         7  
25              
26             has year => (is => 'rw', predicate => 1);
27             has month => (is => 'rw', predicate => 1);
28             has date => (is => 'ro', default => sub { Date::Hebrew::Simple->new });
29              
30             sub BUILD {
31 0     0 0   my ($self) = @_;
32              
33 0 0         $self->date->validate_year($self->year) if $self->has_year;
34 0 0         $self->date->validate_hebrew_month($self->month, $self->year) if $self->has_month;
35              
36 0 0 0       unless ($self->has_year && $self->has_month) {
37 0           $self->year($self->date->year);
38 0           $self->month($self->date->month);
39             }
40             }
41              
42             =head1 DESCRIPTION
43              
44             The C was released on Sunday 23rd July 2017 to mark the completion
45             of L<1000th consecutive days of releasing to CPAN|http://blogs.perl.org/users/mohammad_s_anwar/2017/07/1000th-consecutive-days-releasing-to-cpan.html>.
46              
47             The Hebrew or Jewish calendar is a lunisolar calendar used today predominantly
48             for Jewish religious observances. It determines the dates for Jewish holidays and
49             the appropriate public reading of Torah portions, yahrzeits (dates to commemorate
50             the death of a relative), and daily Psalm readings, among many ceremonial uses.
51              
52             The Hebrew lunar year is about eleven days shorter than the solar year and uses
53             the 19-year Metonic cycle to bring it into line with the solar year, with the
54             addition of an intercalary month every two or three years, for a total of seven
55             times per 19 years. Even with this intercalation, the average Hebrew calendar
56             year is longer by about 6 minutes and 40 seconds than the current mean tropical
57             year, so that every 216 years the Hebrew calendar will fall a day behind the
58             current mean tropical year; and about every 231 years it will fall a day behind
59             the mean Gregorian calendar year.
60              
61             +--------------------------------------------------------------------------------------------------------+
62             | Tammuz [5777 BE] |
63             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
64             | Yom Rishon | Yom Sheni | Yom Shelishi | Yom Revil | Yom Hamishi | Yom Shishi | Shabbat |
65             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
66             | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
67             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
68             | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
69             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
70             | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
71             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
72             | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
73             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
74             | 29 | |
75             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
76              
77             The package L provides command line tool C to display the
78             supported calendars on the terminal. Support for C is provided
79             by L v0.16 or above.
80              
81             =head1 SYNOPSIS
82              
83             use strict; use warnings;
84             use Calendar::Hebrew;
85              
86             # prints current month calendar
87             print Calendar::Hebrew->new, "\n";
88             print Calendar::Hebrew->new->current, "\n";
89              
90             # prints hebrew month calendar in which the given gregorian date falls in.
91             print Calendar::Hebrew->new->from_gregorian(2015, 1, 14), "\n";
92              
93             # prints hebrew month calendar in which the given julian day falls in.
94             print Calendar::Hebrew->new->from_julian(2457102.5), "\n";
95              
96             # prints current month hebrew calendar in SVG format.
97             print Calendar::Hebrew->new->as_svg;
98              
99             # prints current month hebrewn calendar in text format.
100             print Calendar::Hebrew->new->as_text;
101              
102             =head1 HEBREW MONTHS
103              
104             +-------+-------------------------------------------------------------------+
105             | Month | Hebrew Name |
106             +-------+-------------------------------------------------------------------+
107             | 1 | Nisan |
108             | 2 | Iyar |
109             | 3 | Sivan |
110             | 4 | Tammuz |
111             | 5 | Av |
112             | 6 | Elul |
113             | 7 | Tishrei |
114             | 8 | Cheshvan |
115             | 9 | Kislev |
116             | 10 | Tevet |
117             | 11 | Shevat |
118             | 12 | Adar |
119             +-------+-------------------------------------------------------------------+
120              
121             In leap years (such as 5774) an additional month, Adar I (30 days) is added after
122             Shevat, while the regular Adar is referred to as "Adar II."
123              
124             =head1 HEBREW DAYS
125              
126             +-------+---------------+---------------------------------------------------+
127             | Index | Hebrew Name | English Name |
128             +-------+---------------+---------------------------------------------------+
129             | 0 | Yom Rishon | Sunday |
130             | 1 | Yom Sheni | Monday |
131             | 2 | Yom Shelishi | Tuesday |
132             | 3 | Yom Revil | Wednesday |
133             | 4 | Yom Hamishi | Thursday |
134             | 5 | Yom Shishi | Friday |
135             | 6 | Shabbat | Saturday |
136             +-------+---------------+---------------------------------------------------+
137              
138              
139             =head1 CONSTRUCTOR
140              
141             It expects month and year optionally. By default it gets current Hebrew month and
142             year.
143              
144             =head1 METHODS
145              
146             =head2 current()
147              
148             Returns current month of the Hebrew calendar.
149              
150             =cut
151              
152             sub current {
153 0     0 1   my ($self) = @_;
154              
155 0           return $self->as_text($self->date->month, $self->date->year);
156             }
157              
158             =head2 from_gregorian($year, $month, $day)
159              
160             Returns hebrew month calendar in which the given gregorian date falls in.
161              
162             =cut
163              
164             sub from_gregorian {
165 0     0 1   my ($self, $year, $month, $day) = @_;
166              
167 0           return $self->from_julian($self->date->gregorian_to_julian($year, $month, $day));
168             }
169              
170             =head2 from_julian($julian_day)
171              
172             Returns hebrew month calendar in which the given julian day falls in.
173              
174             =cut
175              
176             sub from_julian {
177 0     0 1   my ($self, $julian_day) = @_;
178              
179 0           my $date = $self->date->from_julian($julian_day);
180 0           return $self->as_text($date->month, $date->year);
181             }
182              
183             =head2 as_svg($month, $year)
184              
185             Returns calendar for the given C<$month> and C<$year> rendered in SVG format. If
186             C<$month> and C<$year> missing, it would return current calendar month.
187              
188             =cut
189              
190             sub as_svg {
191 0     0 1   my ($self, $month, $year) = @_;
192              
193 0           ($month, $year) = $self->validate_params($month, $year);
194 0           my $date = Date::Hebrew::Simple->new({ year => $year, month => $month, day => 1 });
195              
196 0           return $self->svg_calendar({
197             start_index => $date->day_of_week,
198             month_name => $date->get_month_name,
199             days => $date->days_in_month_year($month, $year),
200             year => $year });
201             }
202              
203             =head2 as_text($month, $year)
204              
205             Returns color coded Hebrew calendar for the given C<$month> and C<$year>. If
206             C<$month> and C<$year> missing, it would return current calendar month.
207              
208             =cut
209              
210             sub as_text {
211 0     0 1   my ($self, $month, $year) = @_;
212              
213 0           ($month, $year) = $self->validate_params($month, $year);
214 0           my $date = Date::Hebrew::Simple->new({ year => $year, month => $month, day => 1 });
215              
216 0           return $self->text_calendar(
217             {
218             start_index => $date->day_of_week,
219             month_name => $date->get_month_name,
220             days => $date->days_in_month_year($month, $year),
221             day_names => $date->days,
222             year => $year
223             });
224             }
225              
226             sub as_string {
227 0     0 0   my ($self) = @_;
228              
229 0           return $self->as_text($self->month, $self->year);
230             }
231              
232             #
233             #
234             # Override validate_params()
235             sub validate_params {
236 0     0 0   my ($self, $month, $year) = @_;
237              
238 0 0         $month = $self->month unless defined $month;
239 0 0         $year = $self->year unless defined $year;
240              
241 0           $self->date->validate_year($year);
242 0           $self->date->validate_hebrew_month($month, $year);
243              
244 0           return ($month, $year);
245             }
246              
247             =head1 AUTHOR
248              
249             Mohammad S Anwar, C<< >>
250              
251             =head1 REPOSITORY
252              
253             L
254              
255             =head1 ACKNOWLEDGEMENTS
256              
257             The C namespace was originally owned by Yitzchak Scott-Thoennes.
258             Yitzchak has kindly transferred the ownership to me, so that I can keep working on
259             it.
260              
261             =head1 SEE ALSO
262              
263             =over 4
264              
265             =item L
266              
267             =item L
268              
269             =item L
270              
271             =item L
272              
273             =item L
274              
275             =back
276              
277             =head1 BUGS
278              
279             Please report any bugs or feature requests to C,
280             or through the web interface at L.
281             I will be notified, and then you'll automatically be notified of progress on your
282             bug as I make changes.
283              
284             =head1 SUPPORT
285              
286             You can find documentation for this module with the perldoc command.
287              
288             perldoc Calendar::Hebrew
289              
290             You can also look for information at:
291              
292             =over 4
293              
294             =item * RT: CPAN's request tracker
295              
296             L
297              
298             =item * AnnoCPAN: Annotated CPAN documentation
299              
300             L
301              
302             =item * CPAN Ratings
303              
304             L
305              
306             =item * Search CPAN
307              
308             L
309              
310             =back
311              
312             =head1 LICENSE AND COPYRIGHT
313              
314             Copyright (C) 2017 Mohammad S Anwar.
315              
316             This program is free software; you can redistribute it and/or modify it under
317             the terms of the the Artistic License (2.0). You may obtain a copy of the full
318             license at:
319              
320             L
321              
322             Any use, modification, and distribution of the Standard or Modified Versions is
323             governed by this Artistic License.By using, modifying or distributing the Package,
324             you accept this license. Do not use, modify, or distribute the Package, if you do
325             not accept this license.
326              
327             If your Modified Version has been derived from a Modified Version made by someone
328             other than you,you are nevertheless required to ensure that your Modified Version
329             complies with the requirements of this license.
330              
331             This license does not grant you the right to use any trademark, service mark,
332             tradename, or logo of the Copyright Holder.
333              
334             This license includes the non-exclusive, worldwide, free-of-charge patent license
335             to make, have made, use, offer to sell, sell, import and otherwise transfer the
336             Package with respect to any patent claims licensable by the Copyright Holder that
337             are necessarily infringed by the Package. If you institute patent litigation
338             (including a cross-claim or counterclaim) against any party alleging that the
339             Package constitutes direct or contributory patent infringement,then this Artistic
340             License to you shall terminate on the date that such litigation is filed.
341              
342             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
343             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
344             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
345             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
346             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
347             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
348             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
349              
350             =cut
351              
352             1; # End of Calendar::Hebrew