blib/lib/Calendar/Hijri.pm

filter: Statementstmt 50.0% 24 / 48 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 6 / 14 Podpod 71.4% 5 / 7 totaltotal 43.7% 35 / 80 CC 5 SCAR 22.4
CC
5
Cov
42%
BUILD
30.0
current
2.0
from_gregorian
2.0
CRAP 9.4
↑ Summary
1 package Calendar::Hijri;
2  
3 =head1 NAME
4  
5 Calendar::Hijri - Interface to Islamic Calendar.
6  
7 =head1 VERSION
8  
9 Version 0.36
10  
11 =cut
12  
13 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use Date::Hijri::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 with 'Calendar::Plugin::Renderer';
20  
21 4 ▶use overload q{""} => 'as_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 4 $Calendar::Hijri::VERSION = '0.36';
24 4 $Calendar::Hijri::AUTHORITY = 'cpan:MANWAR';
25  
26 4 has year => (is => 'rw', predicate => 1);
27 4 has month => (is => 'rw', predicate => 1);
28 0 ▶has date => (is => 'ro', default => sub { Date::Hijri::Simple->new });
Subroutine __ANON__: not called CC=1 SCAR=1.2
29  
30 sub BUILD {
31 0 ▶ my ($self) = @_;
Subroutine BUILD: not called CC=5 SCAR=34.0
Pod undocumented
32  
33 0 ▶ $self->date->validate_year($self->year) if $self->has_year;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_year 0 0 0
34 0 ▶ $self->date->validate_month($self->month) if $self->has_month;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_month 0 0 0
35  
36 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
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<App::calendr> provides command line tool C<calendr> 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 ▶ my ($self) = @_;
Subroutine current: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self, $year, $month, $day) = @_;
Subroutine from_gregorian: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self, $julian) = @_;
Subroutine from_julian: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self, $month, $year) = @_;
Subroutine as_text: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self, $month, $year) = @_;
Subroutine as_svg: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self) = @_;
Subroutine as_string: not called CC=1 SCAR=6.9
Pod undocumented
216  
217 0 return $self->as_text($self->month, $self->year);
218 }
219  
220 =head1 AUTHOR
221  
222 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
223  
224 =head1 REPOSITORY
225  
226 L<https://github.com/manwar/Calendar-Hijri>
227  
228 =head1 SEE ALSO
229  
230 =over 4
231  
232 =item L<Calendar::Bahai>
233  
234 =item L<Calendar::Gregorian>
235  
236 =item L<Calendar::Persian>
237  
238 =item L<Calendar::Saka>
239  
240 =back
241  
242 =head1 BUGS
243  
244 Please report any bugs / feature requests to C<bug-calendar-hijri at rt.cpan.org>
245 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Calendar-Hijri>.
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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Calendar-Hijri>
262  
263 =item * AnnoCPAN: Annotated CPAN documentation
264  
265 L<http://annocpan.org/dist/Calendar-Hijri>
266  
267 =item * CPAN Ratings
268  
269 L<http://cpanratings.perl.org/d/Calendar-Hijri>
270  
271 =item * Search CPAN
272  
273 L<http://search.cpan.org/dist/Calendar-Hijri/>
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<http://www.perlfoundation.org/artistic_license_2_0>
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 4 1; # End of Calendar::Hijri
↑ Summary