line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Date::Utils::Saka; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$Date::Utils::Saka::VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Date::Utils::Saka - Saka date specific routines as Moo Role. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Version 0.01 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
12516
|
use 5.006; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
16
|
1
|
|
|
1
|
|
532
|
use Data::Dumper; |
|
1
|
|
|
|
|
5963
|
|
|
1
|
|
|
|
|
61
|
|
17
|
1
|
|
|
1
|
|
8
|
use List::Util qw/min/; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
74
|
|
18
|
1
|
|
|
1
|
|
432
|
use POSIX qw/floor/; |
|
1
|
|
|
|
|
4342
|
|
|
1
|
|
|
|
|
6
|
|
19
|
1
|
|
|
1
|
|
6692
|
use Date::Calc qw/Delta_Days/; |
|
1
|
|
|
|
|
9169
|
|
|
1
|
|
|
|
|
98
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
588
|
use Moo::Role; |
|
1
|
|
|
|
|
13887
|
|
|
1
|
|
|
|
|
4
|
|
22
|
1
|
|
|
1
|
|
606
|
use namespace::clean; |
|
1
|
|
|
|
|
7602
|
|
|
1
|
|
|
|
|
5
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $SAKA_START = 80; |
25
|
|
|
|
|
|
|
my $SAKA_OFFSET = 78; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $SAKA_MONTHS = [ |
28
|
|
|
|
|
|
|
undef, |
29
|
|
|
|
|
|
|
'Chaitra', 'Vaisakha', 'Jyaistha', 'Asadha', 'Sravana', 'Bhadra', |
30
|
|
|
|
|
|
|
'Asvina', 'Kartika', 'Agrahayana', 'Pausa', 'Magha', 'Phalguna' |
31
|
|
|
|
|
|
|
]; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $SAKA_DAYS = [ |
34
|
|
|
|
|
|
|
' Ravivara ', |
35
|
|
|
|
|
|
|
' Somvara ', |
36
|
|
|
|
|
|
|
' Mangalavara ', |
37
|
|
|
|
|
|
|
' Budhavara ', |
38
|
|
|
|
|
|
|
' Brahaspativara ', |
39
|
|
|
|
|
|
|
' Sukravara ', |
40
|
|
|
|
|
|
|
' Sanivara ', |
41
|
|
|
|
|
|
|
]; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has saka_days => (is => 'ro', default => sub { $SAKA_DAYS }); |
44
|
|
|
|
|
|
|
has saka_months => (is => 'ro', default => sub { $SAKA_MONTHS }); |
45
|
|
|
|
|
|
|
has saka_start => (is => 'ro', default => sub { $SAKA_START }); |
46
|
|
|
|
|
|
|
has saka_offset => (is => 'ro', default => sub { $SAKA_OFFSET }); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
with 'Date::Utils'; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Saka date specific routines as Moo Role. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 METHODS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 saka_to_gregorian($year, $month, $day) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub saka_to_gregorian { |
61
|
0
|
|
|
0
|
1
|
|
my ($self, $year, $month, $day) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $self->julian_to_gregorian($self->saka_to_julian($year, $month, $day)); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 gregorian_to_sake($year, $month, $day) |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub gregorian_to_saka { |
71
|
0
|
|
|
0
|
0
|
|
my ($self, $year, $month, $day) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return $self->julian_to_saka($self->gregorian_to_julian($year, $month, $day)); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 julian_to_saka() |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub julian_to_saka { |
81
|
0
|
|
|
0
|
1
|
|
my ($self, $julian) = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
$julian = floor($julian) + 0.5; |
84
|
0
|
|
|
|
|
|
my $year = ($self->julian_to_gregorian($julian))[0]; |
85
|
0
|
|
|
|
|
|
my $yday = $julian - $self->gregorian_to_julian($year, 1, 1); |
86
|
0
|
|
|
|
|
|
my $chaitra = $self->days_in_chaitra($year); |
87
|
0
|
|
|
|
|
|
$year = $year - $self->saka_offset; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if ($yday < $self->saka_start) { |
90
|
0
|
|
|
|
|
|
$year--; |
91
|
0
|
|
|
|
|
|
$yday += $chaitra + (31 * 5) + (30 * 3) + 10 + $self->saka_start; |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
$yday -= $self->saka_start; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my ($day, $month); |
96
|
0
|
0
|
|
|
|
|
if ($yday < $chaitra) { |
97
|
0
|
|
|
|
|
|
$month = 1; |
98
|
0
|
|
|
|
|
|
$day = $yday + 1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
0
|
|
|
|
|
|
my $mday = $yday - $chaitra; |
102
|
0
|
0
|
|
|
|
|
if ($mday < (31 * 5)) { |
103
|
0
|
|
|
|
|
|
$month = floor($mday / 31) + 2; |
104
|
0
|
|
|
|
|
|
$day = ($mday % 31) + 1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
0
|
|
|
|
|
|
$mday -= 31 * 5; |
108
|
0
|
|
|
|
|
|
$month = floor($mday / 30) + 7; |
109
|
0
|
|
|
|
|
|
$day = ($mday % 30) + 1; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return ($year, $month, $day); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 saka_to_julian($year, $month, $day) |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub saka_to_julian { |
121
|
0
|
|
|
0
|
1
|
|
my ($self, $year, $month, $day) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my $gregorian_year = $year + 78; |
124
|
0
|
0
|
|
|
|
|
my $gregorian_day = ($self->is_gregorian_leap_year($gregorian_year)) ? (21) : (22); |
125
|
0
|
|
|
|
|
|
my $start = $self->gregorian_to_julian($gregorian_year, 3, $gregorian_day); |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my ($julian); |
128
|
0
|
0
|
|
|
|
|
if ($month == 1) { |
129
|
0
|
|
|
|
|
|
$julian = $start + ($day - 1); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else { |
132
|
0
|
0
|
|
|
|
|
my $chaitra = ($self->is_gregorian_leap_year($gregorian_year)) ? (31) : (30); |
133
|
0
|
|
|
|
|
|
$julian = $start + $chaitra; |
134
|
0
|
|
|
|
|
|
my $_month = $month - 2; |
135
|
0
|
|
|
|
|
|
$_month = min($_month, 5); |
136
|
0
|
|
|
|
|
|
$julian += $_month * 31; |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
if ($month >= 8) { |
139
|
0
|
|
|
|
|
|
$_month = $month - 7; |
140
|
0
|
|
|
|
|
|
$julian += $_month * 30; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
$julian += $day - 1; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return $julian; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 days_in_chaitra($year) |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub days_in_chaitra { |
154
|
0
|
|
|
0
|
1
|
|
my ($self, $year) = @_; |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
|
|
|
|
($self->is_gregorian_leap_year($year)) ? (return 31) : (return 30); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 days_in_saka_month_year($month, $year) |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub days_in_saka_month_year { |
164
|
0
|
|
|
0
|
1
|
|
my ($self, $month, $year) = @_; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
my @start = $self->saka_to_gregorian($year, $month, 1); |
167
|
0
|
0
|
|
|
|
|
if ($month == 12) { |
168
|
0
|
|
|
|
|
|
$year += 1; |
169
|
0
|
|
|
|
|
|
$month = 1; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
else { |
172
|
0
|
|
|
|
|
|
$month += 1; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
my @end = $self->saka_to_gregorian($year, $month, 1); |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
return Delta_Days(@start, @end); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 AUTHOR |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Mohammad S Anwar, C<< >> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 REPOSITORY |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Entire logic is based on the L written by John Walker. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 BUGS |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Please report any bugs / feature requests to C |
195
|
|
|
|
|
|
|
, or through the web interface at L. |
196
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on your |
197
|
|
|
|
|
|
|
bug as I make changes. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 SUPPORT |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
perldoc Date::Utils::Saka |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
You can also look for information at: |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=over 4 |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
L |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * CPAN Ratings |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
L |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item * Search CPAN |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
L |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=back |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Copyright (C) 2015 Mohammad S Anwar. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
This program is free software; you can redistribute it and / or modify it under |
232
|
|
|
|
|
|
|
the terms of the the Artistic License (2.0). You may obtain a copy of the full |
233
|
|
|
|
|
|
|
license at: |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
L |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified Versions is |
238
|
|
|
|
|
|
|
governed by this Artistic License.By using, modifying or distributing the Package, |
239
|
|
|
|
|
|
|
you accept this license. Do not use, modify, or distribute the Package, if you do |
240
|
|
|
|
|
|
|
not accept this license. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made by someone |
243
|
|
|
|
|
|
|
other than you,you are nevertheless required to ensure that your Modified Version |
244
|
|
|
|
|
|
|
complies with the requirements of this license. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service mark, |
247
|
|
|
|
|
|
|
tradename, or logo of the Copyright Holder. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge patent license |
250
|
|
|
|
|
|
|
to make, have made, use, offer to sell, sell, import and otherwise transfer the |
251
|
|
|
|
|
|
|
Package with respect to any patent claims licensable by the Copyright Holder that |
252
|
|
|
|
|
|
|
are necessarily infringed by the Package. If you institute patent litigation |
253
|
|
|
|
|
|
|
(including a cross-claim or counterclaim) against any party alleging that the |
254
|
|
|
|
|
|
|
Package constitutes direct or contributory patent infringement,then this Artistic |
255
|
|
|
|
|
|
|
License to you shall terminate on the date that such litigation is filed. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND |
258
|
|
|
|
|
|
|
CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED |
259
|
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR |
260
|
|
|
|
|
|
|
NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS |
261
|
|
|
|
|
|
|
REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, |
262
|
|
|
|
|
|
|
INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE |
263
|
|
|
|
|
|
|
OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=cut |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
1; # End of Date::Utils::Saka |