File Coverage

blib/lib/Calendar/Hijri.pm
Criterion Covered Total %
statement 17 40 42.5
branch 0 6 0.0
condition 0 3 0.0
subroutine 6 13 46.1
pod 5 7 71.4
total 28 69 40.5


line stmt bran cond sub pod time code
1             package Calendar::Hijri;
2              
3             $Calendar::Hijri::VERSION = '0.33';
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.33
13              
14             =cut
15              
16 4     4   34677 use 5.006;
  4         12  
17 4     4   2495 use Data::Dumper;
  4         30243  
  4         227  
18              
19 4     4   1763 use Date::Hijri::Simple;
  4         293087  
  4         112  
20 4     4   26 use Moo;
  4         3  
  4         11  
21 4     4   721 use namespace::clean;
  4         4  
  4         12  
22             with 'Calendar::Plugin::Renderer';
23              
24 4     4   508 use overload q{""} => 'as_string', fallback => 1;
  4         5  
  4         24  
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             =head1 AUTHOR
221              
222             Mohammad S Anwar, C<< >>
223              
224             =head1 REPOSITORY
225              
226             L
227              
228             =head1 SEE ALSO
229              
230             =over 4
231              
232             =item L
233              
234             =item L
235              
236             =item L
237              
238             =item L
239              
240             =back
241              
242             =head1 BUGS
243              
244             Please report any bugs / feature requests to C
245             or through the web interface at L.
246             I will be notified, and then you'll automatically be notified of progress on your
247             bug as I make changes.
248              
249             =head1 SUPPORT
250              
251             You can find documentation for this module with the perldoc command.
252              
253             perldoc Calendar::Hijri
254              
255             You can also look for information at:
256              
257             =over 4
258              
259             =item * RT: CPAN's request tracker
260              
261             L
262              
263             =item * AnnoCPAN: Annotated CPAN documentation
264              
265             L
266              
267             =item * CPAN Ratings
268              
269             L
270              
271             =item * Search CPAN
272              
273             L
274              
275             =back
276              
277             =head1 LICENSE AND COPYRIGHT
278              
279             Copyright (C) 2011 - 2016 Mohammad S Anwar.
280              
281             This program is free software; you can redistribute it and / or modify it under
282             the terms of the the Artistic License (2.0). You may obtain a copy of the full
283             license at:
284              
285             L
286              
287             Any use, modification, and distribution of the Standard or Modified Versions is
288             governed by this Artistic License.By using, modifying or distributing the Package,
289             you accept this license. Do not use, modify, or distribute the Package, if you do
290             not accept this license.
291              
292             If your Modified Version has been derived from a Modified Version made by someone
293             other than you,you are nevertheless required to ensure that your Modified Version
294             complies with the requirements of this license.
295              
296             This license does not grant you the right to use any trademark, service mark,
297             tradename, or logo of the Copyright Holder.
298              
299             This license includes the non-exclusive, worldwide, free-of-charge patent license
300             to make, have made, use, offer to sell, sell, import and otherwise transfer the
301             Package with respect to any patent claims licensable by the Copyright Holder that
302             are necessarily infringed by the Package. If you institute patent litigation
303             (including a cross-claim or counterclaim) against any party alleging that the
304             Package constitutes direct or contributory patent infringement,then this Artistic
305             License to you shall terminate on the date that such litigation is filed.
306              
307             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
308             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
309             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
310             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
311             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
312             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
313             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
314              
315             =cut
316              
317             1; # End of Calendar::Hijri