File Coverage

blib/lib/Calendar/Hijri.pm
Criterion Covered Total %
statement 17 49 34.6
branch 0 10 0.0
condition 0 6 0.0
subroutine 6 14 42.8
pod 5 8 62.5
total 28 87 32.1


line stmt bran cond sub pod time code
1             package Calendar::Hijri;
2              
3             $Calendar::Hijri::VERSION = '0.31';
4             $Calendar::Hijri::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Calendar::Hijri - Interface to Islamic Calendar.
9              
10             =head1 VERSION
11              
12             Version 0.31
13              
14             =cut
15              
16 4     4   27645 use 5.006;
  4         9  
17 4     4   2078 use Data::Dumper;
  4         25050  
  4         179  
18              
19 4     4   1715 use Date::Hijri::Simple;
  4         281318  
  4         106  
20 4     4   23 use Moo;
  4         5  
  4         9  
21 4     4   701 use namespace::clean;
  4         4  
  4         11  
22             with 'Calendar::Plugin::Renderer';
23              
24 4     4   528 use overload q{""} => 'as_string', fallback => 1;
  4         5  
  4         20  
25              
26             has year => (is => 'rw', predicate => 1);
27             has month => (is => 'rw', predicate => 1);
28             has date => (is => 'ro', default => sub { Date::Hijri::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_month($self->month) 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             Hijri Calendar begins with the migration from Mecca to Medina of Mohammad (pbuh),
45             the Prophet of Islam, an event known as the Hegira. The initials A.H. before a
46             date mean "anno Hegirae" or "after Hegira". The first day of the year is fixed
47             in the Quran as the first day of the month of Muharram.In 17 AH Umar I,the second
48             caliph, established the beginning of the era of the Hegira ( 1 Muharram 1 AH ) as
49             the date that is 16 July 622 CE in the Julian Calendar.
50              
51             The years are lunar & consist of 12 lunar months. There is no intercalary period,
52             since the Quran ( Sura IX, verses 36,37 ) sets the calendar year at 12 months.
53             Because the year in the Hijri calendar is shorter than a solar year, the months
54             drift with respect to the seasons, in a cycle 32.50 years.
55              
56             +--------------------------------------------------------------------------------------------------------+
57             | Sha'aban [1436 BE] |
58             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
59             | al-Ahad | al-Ithnayn | ath-Thulatha | al-Arbia | al-Khamis | al-Jumuah | as-Sabt |
60             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
61             | | 1 | 2 | 3 | 4 |
62             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
63             | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
64             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
65             | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
66             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
67             | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
68             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
69             | 26 | 27 | 28 | 29 | |
70             +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
71              
72             The package L provides command line tool C to display the
73             supported calendars on the terminal.
74              
75             =head1 SYNOPSIS
76              
77             use strict; use warnings;
78             use Calendar::Hijri;
79              
80             # prints current hijri month calendar.
81             print Calendar::Hijri->new, "\n";
82             print Calendar::Hijri->new->current, "\n";
83              
84             # prints hijri month calendar for the first month of year 1436.
85             print Calendar::Hijri->new({ month => 1, year => 1436 }), "\n";
86              
87             # prints hijri month calendar in which the given gregorian date falls in.
88             print Calendar::Hijri->new->from_gregorian(2015, 1, 14), "\n";
89              
90             # prints hijri month calendar in which the given julian date falls in.
91             print Calendar::Hijri->new->from_julian(2457102.5), "\n";
92              
93             # prints current month hijri calendar in SVG format.
94             print Calendar::Hijri->new->as_svg;
95              
96             # prints current month hijri calendar in text format.
97             print Calendar::Hijri->new->as_text;
98              
99             =head1 HIJRI MONTHS
100              
101             +--------+------------------------------------------------------------------+
102             | Number | Name |
103             +--------+------------------------------------------------------------------+
104             | 1 | Muharram |
105             | 2 | Safar |
106             | 3 | Rabi' al-awwal |
107             | 4 | Rabi' al-thani |
108             | 5 | Jumada al-awwal |
109             | 6 | Jumada al-thani |
110             | 7 | Rajab |
111             | 8 | Sha'aban |
112             | 9 | Ramadan |
113             | 10 | Shawwal |
114             | 11 | Dhu al-Qi'dah |
115             | 12 | Dhu al-Hijjah |
116             +--------+------------------------------------------------------------------+
117              
118             =head1 HIJRI DAYS
119              
120             +--------------+------------------------------------------------------------+
121             | Arabic Name | English Name |
122             +--------------+------------------------------------------------------------+
123             | al-Ahad | Sunday |
124             | al-Ithnayn | Monday |
125             | ath-Thulatha | Tuesday |
126             | al-Arbia | Wednesday |
127             | al-Khamis | Thursday |
128             | al-Jumuah | Friday |
129             | as-Sabt | Saturday |
130             +--------------+------------------------------------------------------------+
131              
132             =head1 METHODS
133              
134             =head2 current()
135              
136             Returns current month of the Hijri calendar.
137              
138             =cut
139              
140             sub current {
141 0     0 1   my ($self) = @_;
142              
143 0           return $self->as_text($self->date->month, $self->date->year);
144             }
145              
146             =head2 from_gregorian()
147              
148             Returns Hijri month calendar in which the given gregorian date falls in.
149              
150             =cut
151              
152             sub from_gregorian {
153 0     0 1   my ($self, $year, $month, $day) = @_;
154              
155 0           return $self->from_julian($self->date->gregorian_to_julian($year, $month, $day));
156             }
157              
158             =head2 from_julian($julian_date)
159              
160             Returns Hijri month calendar in which the given julian date falls in.
161              
162             =cut
163              
164             sub from_julian {
165 0     0 1   my ($self, $julian) = @_;
166              
167 0           my $date = $self->date->from_julian($julian);
168 0           return $self->as_text($date->month, $date->year);
169             }
170              
171             =head2 as_text($month, $year)
172              
173             Returns color coded Hijri calendar for the given C<$month> and C<$year>. If
174             C<$month> and C<$year> missing, it would return current calendar month.
175              
176             =cut
177              
178             sub as_text {
179 0     0 1   my ($self, $month, $year) = @_;
180              
181 0           ($month, $year) = $self->validate_params($month, $year);
182 0           my $date = Date::Hijri::Simple->new({ year => $year, month => $month, day => 1 });
183              
184 0           return $self->text_calendar(
185             {
186             start_index => $date->day_of_week,
187             month_name => $date->get_month_name,
188             days => $date->days_in_month_year($month, $year),
189             year => $year,
190             day_names => $date->days,
191             });
192             }
193              
194             =head2 as_svg($month, $year)
195              
196             Returns calendar for the given C<$month> and C<$year> rendered in SVG format. If
197             C<$month> and C<$year> missing, it would return current calendar month.
198              
199             =cut
200              
201             sub as_svg {
202 0     0 1   my ($self, $month, $year) = @_;
203              
204 0           ($month, $year) = $self->validate_params($month, $year);
205 0           my $date = Date::Hijri::Simple->new({ year => $year, month => $month, day => 1 });
206              
207 0           return $self->svg_calendar({
208             start_index => $date->day_of_week,
209             month_name => $date->get_month_name,
210             days => $date->days_in_month_year($month, $year),
211             year => $year });
212             }
213              
214             sub as_string {
215 0     0 0   my ($self) = @_;
216              
217 0           return $self->as_text($self->month, $self->year);
218             }
219              
220             #
221             #
222             # PRIVATE METHODS
223              
224             sub validate_params {
225 0     0 0   my ($self, $month, $year) = @_;
226              
227 0 0 0       if (defined $month && defined $year) {
228 0           $self->date->validate_month($month);
229 0           $self->date->validate_year($year);
230              
231 0 0         if ($month !~ /^\d+$/) {
232 0           $month = $self->date->get_month_number($month);
233             }
234             }
235             else {
236 0           $month = $self->month;
237 0           $year = $self->year;
238             }
239              
240 0           return ($month, $year);
241             }
242              
243             =head1 AUTHOR
244              
245             Mohammad S Anwar, C<< >>
246              
247             =head1 REPOSITORY
248              
249             L
250              
251             =head1 SEE ALSO
252              
253             =over 4
254              
255             =item L
256              
257             =item L
258              
259             =item L
260              
261             =item L
262              
263             =back
264              
265             =head1 BUGS
266              
267             Please report any bugs / feature requests to C
268             or through the web interface at L.
269             I will be notified, and then you'll automatically be notified of progress on your
270             bug as I make changes.
271              
272             =head1 SUPPORT
273              
274             You can find documentation for this module with the perldoc command.
275              
276             perldoc Calendar::Hijri
277              
278             You can also look for information at:
279              
280             =over 4
281              
282             =item * RT: CPAN's request tracker
283              
284             L
285              
286             =item * AnnoCPAN: Annotated CPAN documentation
287              
288             L
289              
290             =item * CPAN Ratings
291              
292             L
293              
294             =item * Search CPAN
295              
296             L
297              
298             =back
299              
300             =head1 LICENSE AND COPYRIGHT
301              
302             Copyright (C) 2011 - 2016 Mohammad S Anwar.
303              
304             This program is free software; you can redistribute it and / or modify it under
305             the terms of the the Artistic License (2.0). You may obtain a copy of the full
306             license at:
307              
308             L
309              
310             Any use, modification, and distribution of the Standard or Modified Versions is
311             governed by this Artistic License.By using, modifying or distributing the Package,
312             you accept this license. Do not use, modify, or distribute the Package, if you do
313             not accept this license.
314              
315             If your Modified Version has been derived from a Modified Version made by someone
316             other than you,you are nevertheless required to ensure that your Modified Version
317             complies with the requirements of this license.
318              
319             This license does not grant you the right to use any trademark, service mark,
320             tradename, or logo of the Copyright Holder.
321              
322             This license includes the non-exclusive, worldwide, free-of-charge patent license
323             to make, have made, use, offer to sell, sell, import and otherwise transfer the
324             Package with respect to any patent claims licensable by the Copyright Holder that
325             are necessarily infringed by the Package. If you institute patent litigation
326             (including a cross-claim or counterclaim) against any party alleging that the
327             Package constitutes direct or contributory patent infringement,then this Artistic
328             License to you shall terminate on the date that such litigation is filed.
329              
330             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
331             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
332             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
333             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
334             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
335             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
336             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
337              
338             =cut
339              
340             1; # End of Calendar::Hijri