File Coverage

blib/lib/Calendar/Saka.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::Saka;
2              
3             $Calendar::Saka::VERSION = '1.32';
4             $Calendar::Saka::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Calendar::Saka - Interface to Indian Calendar.
9              
10             =head1 VERSION
11              
12             Version 1.32
13              
14             =cut
15              
16 4     4   30458 use 5.006;
  4         11  
17 4     4   2193 use Data::Dumper;
  4         27632  
  4         234  
18              
19 4     4   1738 use Date::Saka::Simple;
  4         347719  
  4         158  
20 4     4   26 use Moo;
  4         5  
  4         11  
21 4     4   713 use namespace::clean;
  4         6  
  4         13  
22             with 'Calendar::Plugin::Renderer';
23              
24 4     4   580 use overload q{""} => 'as_string', fallback => 1;
  4         6  
  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::Saka::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             Module to play with Saka calendar mostly used in the South indian, Goa and
45             Maharashatra. It supports the functionality to add / minus days, months and years
46             to a Saka date. It can also converts Saka date to Gregorian/Julian date.
47              
48             The Saka eras are lunisolar calendars, and feature annual cycles of twelve lunar
49             months, each month divided into two phases: the 'bright half' (shukla) and the
50             'dark half' (krishna); these correspond respectively to the periods of the
51             'waxing' and the 'waning' of the moon. Thus, the period beginning from the first
52             day after the new moon and ending on the full moon day constitutes the shukla
53             paksha or 'bright half' of the month the period beginning from the day after the
54             full moon until & including the next new moon day constitutes the krishna paksha
55             or 'dark half' of the month.
56              
57             The "year zero" corresponds to 78 BCE in the Saka calendar. The Saka calendar
58             begins with the month of Chaitra (March) and the Ugadi/Gudi Padwa festivals mark
59             the new year.
60              
61             Each month in the Shalivahana calendar begins with the 'bright half' and is
62             followed by the 'dark half'. Thus, each month of the Shalivahana calendar ends
63             with the no-moon day and the new month begins on the day after that.
64              
65             A variant of the Saka Calendar was reformed & standardized as the Indian National
66             calendar in 1957. This official calendar follows the Shalivahan Shak calendar in
67             beginning from the month of Chaitra and counting years with 78 CE being year zero.
68             It features a constant number of days in every month with leap years.Saka Calendar
69             for the month of Chaitra year 1937
70              
71             +----------------------------------------------------------------------------------------------------------------------+
72             | Chaitra [1937 BE] |
73             +----------------+----------------+----------------+----------------+----------------+----------------+----------------+
74             | Ravivara | Somvara | Mangalavara | Budhavara | Brahaspativara | Sukravara | Sanivara |
75             +----------------+----------------+----------------+----------------+----------------+----------------+----------------+
76             | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
77             +----------------+----------------+----------------+----------------+----------------+----------------+----------------+
78             | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
79             +----------------+----------------+----------------+----------------+----------------+----------------+----------------+
80             | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
81             +----------------+----------------+----------------+----------------+----------------+----------------+----------------+
82             | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
83             +----------------+----------------+----------------+----------------+----------------+----------------+----------------+
84             | 29 | 30 | |
85             +----------------+----------------+----------------+----------------+----------------+----------------+----------------+
86              
87             The package L provides command line tool C to display the
88             supported calendars on the terminal.
89              
90             =head1 SYNOPSIS
91              
92             use strict; use warnings;
93             use Calendar::Saka;
94              
95             # prints current saka month calendar.
96             print Calendar::Saka->new->current, "\n";
97              
98             # prints saka month calendar in which the given gregorian date falls in.
99             print Calendar::Saka->new->from_gregorian(2015, 4, 19), "\n";
100              
101             # prints saka month calendar in which the given julian date falls in.
102             print Calendar::Saka->new->from_julian(2457102.5), "\n";
103              
104             # prints current month saka calendar in SVG format.
105             print Calendar::Saka->new->as_svg;
106              
107             # prints current month saka calendar in text format.
108             print Calendar::Saka->new->as_text;
109              
110             =head1 SAKA MONTHS
111              
112             +-------+-------------------------------------------------------------------+
113             | Order | Name |
114             +-------+-------------------------------------------------------------------+
115             | 1 | Chaitra |
116             | 2 | Vaisakha |
117             | 3 | Jyaistha |
118             | 4 | Asadha |
119             | 5 | Sravana |
120             | 6 | Bhadra |
121             | 7 | Asvina |
122             | 8 | Kartika |
123             | 9 | Agrahayana |
124             | 10 | Pausa |
125             | 11 | Magha |
126             | 12 | Phalguna |
127             +-------+-------------------------------------------------------------------+
128              
129             =head1 SAKA DAYS
130              
131             +---------+-----------+-----------------------------------------------------+
132             | Weekday | Gregorian | Saka |
133             +---------+-----------+-----------------------------------------------------+
134             | 0 | Sunday | Ravivara |
135             | 1 | Monday | Somvara |
136             | 2 | Tuesday | Mangalavara |
137             | 3 | Wednesday | Budhavara |
138             | 4 | Thursday | Brahaspativara |
139             | 5 | Friday | Sukravara |
140             | 6 | Saturday | Sanivara |
141             +---------+-----------+-----------------------------------------------------+
142              
143             =head1 METHODS
144              
145             =head2 current()
146              
147             Returns current month of the Saka calendar.
148              
149             =cut
150              
151             sub current {
152 0     0 1   my ($self) = @_;
153              
154 0           return $self->as_text($self->date->month, $self->date->year);
155             }
156              
157             =head2 from_gregorian()
158              
159             Returns saka month calendar in which the given gregorian date falls in.
160              
161             =cut
162              
163             sub from_gregorian {
164 0     0 1   my ($self, $year, $month, $day) = @_;
165              
166 0           return $self->from_julian($self->date->gregorian_to_julian($year, $month, $day));
167             }
168              
169             =head2 from_julian($julian_date)
170              
171             Returns saka month calendar in which the given julian date falls in.
172              
173             =cut
174              
175             sub from_julian {
176 0     0 1   my ($self, $julian) = @_;
177              
178 0           my $date = $self->from_julian($julian);
179 0           return $self->as_text($date->month, $date->year);
180             }
181              
182             =head2 as_svg($month, $year)
183              
184             Returns calendar for the given C<$month> and C<$year> rendered in SVG format. If
185             C<$month> and C<$year> missing, it would return current calendar month.
186              
187             =cut
188              
189             sub as_svg {
190 0     0 1   my ($self, $month, $year) = @_;
191              
192 0           ($month, $year) = $self->validate_params($month, $year);
193 0           my $date = Date::Saka::Simple->new({ year => $year, month => $month, day => 1 });
194              
195 0           return $self->svg_calendar(
196             {
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              
204             =head2 as_text($month, $year)
205              
206             Returns color coded Saka calendar for the given C<$month> and C<$year>. If
207             C<$month> and C<$year> missing, it would return current calendar month.
208              
209             =cut
210              
211             sub as_text {
212 0     0 1   my ($self, $month, $year) = @_;
213              
214 0           ($month, $year) = $self->validate_params($month, $year);
215 0           my $date = Date::Saka::Simple->new({ year => $year, month => $month, day => 1 });
216              
217 0           return $self->text_calendar(
218             {
219             start_index => $date->day_of_week,
220             month_name => $date->get_month_name,
221             days => $date->days_in_month_year($month, $year),
222             day_names => $date->days,
223             year => $year
224             });
225             }
226              
227             sub as_string {
228 0     0 0   my ($self) = @_;
229              
230 0           return $self->as_text($self->month, $self->year);
231             }
232              
233             #
234             #
235             # PRIVATE METHODS
236              
237             sub validate_params {
238 0     0 0   my ($self, $month, $year) = @_;
239              
240 0 0 0       if (defined $month && defined $year) {
241 0           $self->date->validate_month($month);
242 0           $self->date->validate_year($year);
243              
244 0 0         if ($month !~ /^\d+$/) {
245 0           $month = $self->date->get_month_number($month);
246             }
247             }
248             else {
249 0           $month = $self->month;
250 0           $year = $self->year;
251             }
252              
253 0           return ($month, $year);
254             }
255              
256             =head1 AUTHOR
257              
258             Mohammad S Anwar, C<< >>
259              
260             =head1 REPOSITORY
261              
262             L
263              
264             =head1 BUGS
265              
266             Please report any bugs or feature requests to C,
267             or through the web interface at L.
268             I will be notified, and then you'll automatically be notified of progress on your
269             bug as I make changes.
270              
271             =head1 SUPPORT
272              
273             You can find documentation for this module with the perldoc command.
274              
275             perldoc Calendar::Saka
276              
277             You can also look for information at:
278              
279             =over 4
280              
281             =item * RT: CPAN's request tracker
282              
283             L
284              
285             =item * AnnoCPAN: Annotated CPAN documentation
286              
287             L
288              
289             =item * CPAN Ratings
290              
291             L
292              
293             =item * Search CPAN
294              
295             L
296              
297             =back
298              
299             =head1 LICENSE AND COPYRIGHT
300              
301             Copyright (C) 2011 - 2016 Mohammad S Anwar.
302              
303             This program is free software; you can redistribute it and/or modify it under
304             the terms of the the Artistic License (2.0). You may obtain a copy of the full
305             license at:
306              
307             L
308              
309             Any use, modification, and distribution of the Standard or Modified Versions is
310             governed by this Artistic License.By using, modifying or distributing the Package,
311             you accept this license. Do not use, modify, or distribute the Package, if you do
312             not accept this license.
313              
314             If your Modified Version has been derived from a Modified Version made by someone
315             other than you,you are nevertheless required to ensure that your Modified Version
316             complies with the requirements of this license.
317              
318             This license does not grant you the right to use any trademark, service mark,
319             tradename, or logo of the Copyright Holder.
320              
321             This license includes the non-exclusive, worldwide, free-of-charge patent license
322             to make, have made, use, offer to sell, sell, import and otherwise transfer the
323             Package with respect to any patent claims licensable by the Copyright Holder that
324             are necessarily infringed by the Package. If you institute patent litigation
325             (including a cross-claim or counterclaim) against any party alleging that the
326             Package constitutes direct or contributory patent infringement,then this Artistic
327             License to you shall terminate on the date that such litigation is filed.
328              
329             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
330             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
331             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
332             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
333             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
334             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
335             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
336              
337             =cut
338              
339             1; # End of Calendar::Saka