blib/lib/Calendar/Saka.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::Saka;
2  
3 4 $Calendar::Saka::VERSION = '1.39';
4 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.39
13  
14 =cut
15  
16 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 ▶use Date::Saka::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 with 'Calendar::Plugin::Renderer';
23  
24 4 ▶use overload q{""} => 'as_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
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::Saka::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 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<App::calendr> provides command line tool C<calendr> 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 ▶ my ($self) = @_;
Subroutine current: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self, $year, $month, $day) = @_;
Subroutine from_gregorian: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self, $julian) = @_;
Subroutine from_julian: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self, $month, $year) = @_;
Subroutine as_svg: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self, $month, $year) = @_;
Subroutine as_text: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self) = @_;
Subroutine as_string: not called CC=1 SCAR=6.9
Pod undocumented
229  
230 0 return $self->as_text($self->month, $self->year);
231 }
232  
233 =head1 AUTHOR
234  
235 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
236  
237 =head1 REPOSITORY
238  
239 L<https://github.com/manwar/Calendar-Saka>
240  
241 =head1 BUGS
242  
243 Please report any bugs or feature requests to C<bug-calendar-saka at rt.cpan.org>,
244 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Calendar-Saka>.
245 I will be notified, and then you'll automatically be notified of progress on your
246 bug as I make changes.
247  
248 =head1 SUPPORT
249  
250 You can find documentation for this module with the perldoc command.
251  
252 perldoc Calendar::Saka
253  
254 You can also look for information at:
255  
256 =over 4
257  
258 =item * RT: CPAN's request tracker
259  
260 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Calendar-Saka>
261  
262 =item * AnnoCPAN: Annotated CPAN documentation
263  
264 L<http://annocpan.org/dist/Calendar-Saka>
265  
266 =item * CPAN Ratings
267  
268 L<http://cpanratings.perl.org/d/Calendar-Saka>
269  
270 =item * Search CPAN
271  
272 L<http://search.cpan.org/dist/Calendar-Saka/>
273  
274 =back
275  
276 =head1 LICENSE AND COPYRIGHT
277  
278 Copyright (C) 2011 - 2016 Mohammad S Anwar.
279  
280 This program is free software; you can redistribute it and/or modify it under
281 the terms of the the Artistic License (2.0). You may obtain a copy of the full
282 license at:
283  
284 L<http://www.perlfoundation.org/artistic_license_2_0>
285  
286 Any use, modification, and distribution of the Standard or Modified Versions is
287 governed by this Artistic License.By using, modifying or distributing the Package,
288 you accept this license. Do not use, modify, or distribute the Package, if you do
289 not accept this license.
290  
291 If your Modified Version has been derived from a Modified Version made by someone
292 other than you,you are nevertheless required to ensure that your Modified Version
293 complies with the requirements of this license.
294  
295 This license does not grant you the right to use any trademark, service mark,
296 tradename, or logo of the Copyright Holder.
297  
298 This license includes the non-exclusive, worldwide, free-of-charge patent license
299 to make, have made, use, offer to sell, sell, import and otherwise transfer the
300 Package with respect to any patent claims licensable by the Copyright Holder that
301 are necessarily infringed by the Package. If you institute patent litigation
302 (including a cross-claim or counterclaim) against any party alleging that the
303 Package constitutes direct or contributory patent infringement,then this Artistic
304 License to you shall terminate on the date that such litigation is filed.
305  
306 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
307 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
308 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
309 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
310 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
311 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
312 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
313  
314 =cut
315  
316 4 1; # End of Calendar::Saka
↑ Summary