File Coverage

blib/lib/Calendar/Persian.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::Persian;
2              
3             $Calendar::Persian::VERSION = '0.34';
4             $Calendar::Persian::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Calendar::Persian - Interface to Persian Calendar.
9              
10             =head1 VERSION
11              
12             Version 0.34
13              
14             =cut
15              
16 4     4   27987 use 5.006;
  4         9  
17 4     4   2054 use Data::Dumper;
  4         25500  
  4         194  
18              
19 4     4   1688 use Date::Persian::Simple;
  4         318371  
  4         139  
20 4     4   30 use Moo;
  4         6  
  4         16  
21 4     4   769 use namespace::clean;
  4         5  
  4         15  
22             with 'Calendar::Plugin::Renderer';
23              
24 4     4   714 use overload q{""} => 'as_string', fallback => 1;
  4         7  
  4         21  
25              
26             has year => (is => 'rw', predicate => 1);
27             has month => (is => 'rw', predicate => 1);
28             has date => (is => 'ro', default => sub { Date::Persian::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             The Persian calendar is solar, with the particularity that the year defined by
45             two successive, apparent passages of the Sun through the vernal (spring)
46             equinox. It is based on precise astronomical observations, and moreover uses a
47             sophisticated intercalation system, which makes it more accurate than its younger
48             European counterpart,the Gregorian calendar. It is currently used in Iran as the
49             official calendar of the country. The starting point of the current Iranian
50             calendar is the vernal equinox occurred on Friday March 22 of the year A.D. 622.
51             Persian Calendar for the month of Farvadin year 1390.
52              
53             +---------------------------------------------------------------------------------------------------------------+
54             | Farvardin [1394 BE] |
55             +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
56             | Yekshanbeh | Doshanbeh | Seshhanbeh | Chaharshanbeh | Panjshanbeh | Jomeh | Shanbeh |
57             +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
58             | | 1 |
59             +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
60             | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
61             +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
62             | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
63             +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
64             | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
65             +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
66             | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
67             +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
68             | 30 | 31 | |
69             +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
70              
71             The package L provides command line tool C to display the
72             supported calendars on the terminal.
73              
74             =head1 SYNOPSIS
75              
76             use strict; use warnings;
77             use Calendar::Persian;
78              
79             # prints current month calendar
80             print Calendar::Persian->new, "\n";
81             print Calendar::Persian->new->current, "\n";
82              
83             # prints persian month calendar for the first month of year 1394.
84             print Calendar::Persian->new({ month => 1, year => 1394 }), "\n";
85              
86             # prints persian month calendar in which the given gregorian date falls in.
87             print Calendar::Persian->new->from_gregorian(2015, 1, 14), "\n";
88              
89             # prints persian month calendar in which the given julian date falls in.
90             print Calendar::Persian->new->from_julian(2457102.5), "\n";
91              
92             # prints current month persian calendar in SVG format.
93             print Calendar::Persian->new->as_svg;
94              
95             # prints current month persian calendar in text format.
96             print Calendar::Persian->new->as_text;
97              
98             =head1 PERSIAN MONTHS
99              
100             +-------+-------------------------------------------------------------------+
101             | Month | Persian Name |
102             +-------+-------------------------------------------------------------------+
103             | 1 | Farvardin |
104             | 2 | Ordibehesht |
105             | 3 | Xordad |
106             | 4 | Tir |
107             | 5 | Amordad |
108             | 6 | Sahrivar |
109             | 7 | Mehr |
110             | 8 | Aban |
111             | 9 | Azar |
112             | 10 | Dey |
113             | 11 | Bahman |
114             | 12 | Esfand |
115             +-------+-------------------------------------------------------------------+
116              
117             =head1 PERSIAN DAYS
118              
119             +-------+---------------+---------------------------------------------------+
120             | Index | Persian Name | English Name |
121             +-------+---------------+---------------------------------------------------+
122             | 0 | Yekshanbeh | Sunday |
123             | 1 | Doshanbeh | Monday |
124             | 2 | Seshhanbeh | Tuesday |
125             | 3 | Chaharshanbeh | Wednesday |
126             | 4 | Panjshanbeh | Thursday |
127             | 5 | Jomeh | Friday |
128             | 6 | Shanbeh | Saturday |
129             +-------+---------------+---------------------------------------------------+
130              
131             =head1 CONSTRUCTOR
132              
133             It expects month and year optionally.By default it gets current Persian month and
134             year.
135              
136             =head1 METHODS
137              
138             =head2 current()
139              
140             Returns current month of the Persian calendar.
141              
142             =cut
143              
144             sub current {
145 0     0 1   my ($self) = @_;
146              
147 0           return $self->as_text($self->date->month, $self->date->year);
148             }
149              
150             =head2 from_gregorian($year, $month, $day)
151              
152             Returns persian month calendar in which the given gregorian date falls in.
153              
154             =cut
155              
156             sub from_gregorian {
157 0     0 1   my ($self, $year, $month, $day) = @_;
158              
159 0           return $self->from_julian($self->date->gregorian_to_julian($year, $month, $day));
160             }
161              
162             =head2 from_julian($julian_date)
163              
164             Returns persian month calendar in which the given julian date falls in.
165              
166             =cut
167              
168             sub from_julian {
169 0     0 1   my ($self, $julian_date) = @_;
170              
171 0           my $date = $self->date->from_julian($julian_date);
172 0           return $self->as_text($date->month, $date->year);
173             }
174              
175             =head2 as_svg($month, $year)
176              
177             Returns calendar for the given C<$month> and C<$year> rendered in SVG format. If
178             C<$month> and C<$year> missing, it would return current calendar month.
179              
180             =cut
181              
182             sub as_svg {
183 0     0 1   my ($self, $month, $year) = @_;
184              
185 0           ($month, $year) = $self->validate_params($month, $year);
186 0           my $date = Date::Persian::Simple->new({ year => $year, month => $month, day => 1 });
187              
188 0           return $self->svg_calendar({
189             start_index => $date->day_of_week,
190             month_name => $date->get_month_name,
191             days => $date->days_in_month_year($month, $year),
192             year => $year });
193             }
194              
195             =head2 as_text($month, $year)
196              
197             Returns color coded Persian calendar for the given C<$month> and C<$year>. If
198             C<$month> and C<$year> missing, it would return current calendar month.
199              
200             =cut
201              
202             sub as_text {
203 0     0 1   my ($self, $month, $year) = @_;
204              
205 0           ($month, $year) = $self->validate_params($month, $year);
206 0           my $date = Date::Persian::Simple->new({ year => $year, month => $month, day => 1 });
207              
208 0           return $self->text_calendar(
209             {
210             start_index => $date->day_of_week,
211             month_name => $date->get_month_name,
212             days => $date->days_in_month_year($month, $year),
213             day_names => $date->days,
214             year => $year
215             });
216             }
217              
218             sub as_string {
219 0     0 0   my ($self) = @_;
220              
221 0           return $self->as_text($self->month, $self->year);
222             }
223              
224             =head1 AUTHOR
225              
226             Mohammad S Anwar, C<< >>
227              
228             =head1 REPOSITORY
229              
230             L
231              
232             =head1 SEE ALSO
233              
234             =over 4
235              
236             =item L
237              
238             =item L
239              
240             =item L
241              
242             =item L
243              
244             =back
245              
246             =head1 BUGS
247              
248             Please report any bugs or feature requests to C,
249             or through the web interface at L.
250             I will be notified, and then you'll automatically be notified of progress on your
251             bug as I make changes.
252              
253             =head1 SUPPORT
254              
255             You can find documentation for this module with the perldoc command.
256              
257             perldoc Calendar::Persian
258              
259             You can also look for information at:
260              
261             =over 4
262              
263             =item * RT: CPAN's request tracker
264              
265             L
266              
267             =item * AnnoCPAN: Annotated CPAN documentation
268              
269             L
270              
271             =item * CPAN Ratings
272              
273             L
274              
275             =item * Search CPAN
276              
277             L
278              
279             =back
280              
281             =head1 LICENSE AND COPYRIGHT
282              
283             Copyright (C) 2011 - 2016 Mohammad S Anwar.
284              
285             This program is free software; you can redistribute it and/or modify it under
286             the terms of the the Artistic License (2.0). You may obtain a copy of the full
287             license at:
288              
289             L
290              
291             Any use, modification, and distribution of the Standard or Modified Versions is
292             governed by this Artistic License.By using, modifying or distributing the Package,
293             you accept this license. Do not use, modify, or distribute the Package, if you do
294             not accept this license.
295              
296             If your Modified Version has been derived from a Modified Version made by someone
297             other than you,you are nevertheless required to ensure that your Modified Version
298             complies with the requirements of this license.
299              
300             This license does not grant you the right to use any trademark, service mark,
301             tradename, or logo of the Copyright Holder.
302              
303             This license includes the non-exclusive, worldwide, free-of-charge patent license
304             to make, have made, use, offer to sell, sell, import and otherwise transfer the
305             Package with respect to any patent claims licensable by the Copyright Holder that
306             are necessarily infringed by the Package. If you institute patent litigation
307             (including a cross-claim or counterclaim) against any party alleging that the
308             Package constitutes direct or contributory patent infringement,then this Artistic
309             License to you shall terminate on the date that such litigation is filed.
310              
311             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
312             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
313             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
314             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
315             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
316             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
317             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
318              
319             =cut
320              
321             1; # End of Calendar::Persian