| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Date::Utils::Saka; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | $Date::Utils::Saka::VERSION = '0.02'; | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | Date::Utils::Saka - Saka date specific routines as Moo Role. | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 VERSION | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | Version 0.02 | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | =cut | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 2 |  |  | 2 |  | 32706 | use 5.006; | 
|  | 2 |  |  |  |  | 7 |  | 
|  | 2 |  |  |  |  | 88 |  | 
| 16 | 2 |  |  | 2 |  | 1533 | use Data::Dumper; | 
|  | 2 |  |  |  |  | 18706 |  | 
|  | 2 |  |  |  |  | 234 |  | 
| 17 | 2 |  |  | 2 |  | 26 | use List::Util qw/min/; | 
|  | 2 |  |  |  |  | 11 |  | 
|  | 2 |  |  |  |  | 272 |  | 
| 18 | 2 |  |  | 2 |  | 3422 | use POSIX qw/floor/; | 
|  | 2 |  |  |  |  | 12565 |  | 
|  | 2 |  |  |  |  | 20 |  | 
| 19 | 2 |  |  | 2 |  | 3371 | use Date::Calc qw/Delta_Days/; | 
|  | 2 |  |  |  |  | 500027 |  | 
|  | 2 |  |  |  |  | 210 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 2 |  |  | 2 |  | 826 | use Moo::Role; | 
|  | 2 |  |  |  |  | 35758 |  | 
|  | 2 |  |  |  |  | 20 |  | 
| 22 | 2 |  |  | 2 |  | 1659 | use namespace::clean; | 
|  | 2 |  |  |  |  | 15093 |  | 
|  | 2 |  |  |  |  | 16 |  | 
| 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 | 3 |  |  | 3 | 1 | 5 | my ($self, $year, $month, $day) = @_; | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 3 |  |  |  |  | 7 | 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 | 1 |  |  | 1 | 0 | 421 | my ($self, $year, $month, $day) = @_; | 
| 72 |  |  |  |  |  |  |  | 
| 73 | 1 |  |  |  |  | 4 | 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 | 2 |  |  | 2 | 1 | 15 | my ($self, $julian) = @_; | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 2 |  |  |  |  | 5 | $julian     = floor($julian) + 0.5; | 
| 84 | 2 |  |  |  |  | 8 | my $year    = ($self->julian_to_gregorian($julian))[0]; | 
| 85 | 2 |  |  |  |  | 82 | my $yday    = $julian - $self->gregorian_to_julian($year, 1, 1); | 
| 86 | 2 |  |  |  |  | 13 | my $chaitra = $self->days_in_chaitra($year); | 
| 87 | 2 |  |  |  |  | 12 | $year = $year - $self->saka_offset; | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 2 | 50 |  |  |  | 8 | if ($yday < $self->saka_start) { | 
| 90 | 0 |  |  |  |  | 0 | $year--; | 
| 91 | 0 |  |  |  |  | 0 | $yday += $chaitra + (31 * 5) + (30 * 3) + 10 + $self->saka_start; | 
| 92 |  |  |  |  |  |  | } | 
| 93 | 2 |  |  |  |  | 4 | $yday -= $self->saka_start; | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 2 |  |  |  |  | 2 | my ($day, $month); | 
| 96 | 2 | 50 |  |  |  | 23 | if ($yday < $chaitra) { | 
| 97 | 2 |  |  |  |  | 2 | $month = 1; | 
| 98 | 2 |  |  |  |  | 4 | $day   = $yday + 1; | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  | else { | 
| 101 | 0 |  |  |  |  | 0 | my $mday = $yday - $chaitra; | 
| 102 | 0 | 0 |  |  |  | 0 | if ($mday < (31 * 5)) { | 
| 103 | 0 |  |  |  |  | 0 | $month = floor($mday / 31) + 2; | 
| 104 | 0 |  |  |  |  | 0 | $day   = ($mday % 31) + 1; | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  | else { | 
| 107 | 0 |  |  |  |  | 0 | $mday -= 31 * 5; | 
| 108 | 0 |  |  |  |  | 0 | $month = floor($mday / 30) + 7; | 
| 109 | 0 |  |  |  |  | 0 | $day   = ($mday % 30) + 1; | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  |  | 
| 113 | 2 |  |  |  |  | 11 | return ($year, $month, $day); | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =head2 saka_to_julian($year, $month, $day) | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | =cut | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | sub saka_to_julian { | 
| 121 | 4 |  |  | 4 | 1 | 2621 | my ($self, $year, $month, $day) = @_; | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 4 |  |  |  |  | 8 | my $gregorian_year = $year + 78; | 
| 124 | 4 | 50 |  |  |  | 11 | my $gregorian_day  = ($self->is_gregorian_leap_year($gregorian_year)) ? (21) : (22); | 
| 125 | 4 |  |  |  |  | 32 | my $start = $self->gregorian_to_julian($gregorian_year, 3, $gregorian_day); | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 4 |  |  |  |  | 68 | my ($julian); | 
| 128 | 4 | 100 |  |  |  | 7 | if ($month == 1) { | 
| 129 | 3 |  |  |  |  | 5 | $julian = $start + ($day - 1); | 
| 130 |  |  |  |  |  |  | } | 
| 131 |  |  |  |  |  |  | else { | 
| 132 | 1 | 50 |  |  |  | 3 | my $chaitra = ($self->is_gregorian_leap_year($gregorian_year)) ? (31) : (30); | 
| 133 | 1 |  |  |  |  | 4 | $julian = $start + $chaitra; | 
| 134 | 1 |  |  |  |  | 2 | my $_month = $month - 2; | 
| 135 | 1 |  |  |  |  | 9 | $_month = min($_month, 5); | 
| 136 | 1 |  |  |  |  | 2 | $julian += $_month * 31; | 
| 137 |  |  |  |  |  |  |  | 
| 138 | 1 | 50 |  |  |  | 3 | if ($month >= 8) { | 
| 139 | 0 |  |  |  |  | 0 | $_month  = $month - 7; | 
| 140 | 0 |  |  |  |  | 0 | $julian += $_month * 30; | 
| 141 |  |  |  |  |  |  | } | 
| 142 |  |  |  |  |  |  |  | 
| 143 | 1 |  |  |  |  | 2 | $julian += $day - 1; | 
| 144 |  |  |  |  |  |  | } | 
| 145 |  |  |  |  |  |  |  | 
| 146 | 4 |  |  |  |  | 11 | return $julian; | 
| 147 |  |  |  |  |  |  | } | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =head2 days_in_chaitra($year) | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =cut | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | sub days_in_chaitra { | 
| 154 | 3 |  |  | 3 | 1 | 6 | my ($self, $year) = @_; | 
| 155 |  |  |  |  |  |  |  | 
| 156 | 3 | 50 |  |  |  | 7 | ($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 | 1 |  |  | 1 | 1 | 2 | my ($self, $month, $year) = @_; | 
| 165 |  |  |  |  |  |  |  | 
| 166 | 1 |  |  |  |  | 5 | my @start = $self->saka_to_gregorian($year, $month, 1); | 
| 167 | 1 | 50 |  |  |  | 34 | if ($month == 12) { | 
| 168 | 0 |  |  |  |  | 0 | $year += 1; | 
| 169 | 0 |  |  |  |  | 0 | $month = 1; | 
| 170 |  |  |  |  |  |  | } | 
| 171 |  |  |  |  |  |  | else { | 
| 172 | 1 |  |  |  |  | 2 | $month += 1; | 
| 173 |  |  |  |  |  |  | } | 
| 174 |  |  |  |  |  |  |  | 
| 175 | 1 |  |  |  |  | 3 | my @end = $self->saka_to_gregorian($year, $month, 1); | 
| 176 |  |  |  |  |  |  |  | 
| 177 | 1 |  |  |  |  | 41 | 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 |