Jewish/Declination.pm

filter: Statementstmt 55.1% 27 / 49 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 50.0% 35 / 70 CC 7 SCAR 33.5
CC
7
Cov
44%
declination
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 28.5
« Jewish/Haversine.pm ↑ Summary Jewish/Parshah.pm »
1 package DateTime::Event::Jewish::Declination;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use vars qw(@EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 our $VERSION = '0.01';
8 3 @EXPORT_OK = qw(declination %Declination);
9  
10 =head1 NAME
11  
12 Declination - Declination of the sun for each day of the year
13  
14 =head1 SYNOPSIS
15  
16 use Declination qw(declination);
17
18 my $date = DateTime->new(day=>21, month=>3, year=>2010);
19 my $declination = declination($date, 'deg');
20  
21 =cut
22  
23 # When using this table beware that day-of-month runs from 1,
24 # but subscripts into the arrays below run from 0
25  
26  
27 3 ▶use Math::Trig;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 our %Declination=(
30 "Jan"=>[
31 "-23:04",
32 "-22:59",
33 "-22:54",
34 "-22:48",
35 "-22:42",
36  
37 "-22:36",
38 "-22:28",
39 "-22:21",
40 "-22:13",
41 "-22:05",
42  
43 "-21:56",
44 "-21:47",
45 "-21:37",
46 "-21:27",
47 "-21:16",
48  
49 "-21:06",
50 "-20:54",
51 "-20:42",
52 "-20:30",
53 "-20:18",
54  
55 "-20:05",
56 "-19:52",
57 "-19:38",
58 "-19:24",
59 "-19:10",
60 "-18:55",
61 "-18:40",
62 "-18:25",
63 "-18:09",
64 "-17:53",
65  
66 "-17:37",
67 ],
68  
69 "Feb"=>[
70 "-17:20",
71 "-17:03",
72 "-16:46",
73 "-16:28",
74 "-16:10",
75  
76 "-15:52",
77 "-15:34",
78 "-15:15",
79 "-14:56",
80 "-14:37",
81  
82 "-14:18",
83 "-13:58",
84 "-13:38",
85 "-13:18",
86 "-12:59",
87  
88 "-12:37",
89 "-12:16",
90 "-11:55",
91 "-11:34",
92 "-11:13",
93  
94 "-10:52",
95 "-10:30",
96 "-10:08",
97 "-9:46",
98 "-9:24",
99  
100 "-9:02",
101 "-8:39",
102 "-8:17",
103 "-8:03",
104 ],
105  
106 "Mar"=>[
107 "-7:49",
108 "-7:26",
109 "-7:03",
110 "-6:40",
111 "-6:17",
112  
113 "-5:54",
114 "-5:30",
115 "-5:07",
116 "-4:44",
117 "-4:20",
118  
119 "-3:57",
120 "-3:33",
121 "-3:10",
122 "-2:46",
123 "-2:22",
124  
125 "-1:59",
126 "-1:35",
127 "-1:11",
128 "-0:48",
129 "-0:24",
130  
131 "0:00",
132 "0:24",
133 "0:47",
134 "1:11",
135 "1:35",
136  
137 "1:58",
138 "2:22",
139 "2:45",
140 "3:09",
141 "3:32",
142  
143 "3:55",
144 ],
145  
146 "Apr"=>[
147 "4:18",
148 "4:42",
149 "5:05",
150 "5:28",
151 "5:51",
152  
153 "6:13",
154 "6:36",
155 "6:59",
156 "7:21",
157 "7:43",
158  
159 "8:07",
160 "8:28",
161 "8:50",
162 "9:11",
163 "9:33",
164  
165 "9:54",
166 "10:16",
167 "10:37",
168 "10:58",
169 "11:19",
170  
171 "11:39",
172 "12:00",
173 "12:20",
174 "12:40",
175 "13:00",
176  
177 "13:19",
178 "13:38",
179 "13:58",
180 "14:16",
181 "14:35",
182 ],
183  
184 "May"=>[
185 "14:54",
186 "15:12",
187 "15:30",
188 "15:47",
189 "16:05",
190  
191 "16:22",
192 "16:39",
193 "16:55",
194 "17:12",
195 "17:27",
196  
197 "17:43",
198 "17:59",
199 "18:14",
200 "18:29",
201 "18:43",
202  
203 "18:58",
204 "19:11",
205 "19:25",
206 "19:38",
207 "19:51",
208  
209 "20:04",
210 "20:16",
211 "20:28",
212 "20:39",
213 "20:50",
214  
215 "21:01",
216 "21:12",
217 "21:22",
218 "21:31",
219 "21:41",
220  
221 "21:50",
222 ],
223  
224 "Jun"=>[
225 "21:58",
226 "22:06",
227 "22:14",
228 "22:22",
229 "22:29",
230  
231 "22:35",
232 "22:42",
233 "22:47",
234 "22:53",
235 "22:58",
236  
237 "23:02",
238 "23:07",
239 "23:11",
240 "23:14",
241 "23:17",
242  
243 "23:20",
244 "23:22",
245 "23:24",
246 "23:25",
247 "23:26",
248  
249 "23:26",
250 "23:26",
251 "23:26",
252 "23:25",
253 "23:24",
254  
255 "23:23",
256 "23:21",
257 "23:19",
258 "23:16",
259 "23:13",
260 ],
261  
262 "Jul"=>[
263 "23:09",
264 "23:05",
265 "23:01",
266 "22:56",
267 "22:51",
268  
269 "22:45",
270 "22:39",
271 "22:33",
272 "22:26",
273 "22:19",
274  
275 "22:11",
276 "22:04",
277 "21:55",
278 "21:46",
279 "21:37",
280  
281 "21:28",
282 "21:18",
283 "21:08",
284 "20:58",
285 "20:47",
286  
287 "20:36",
288 "20:24",
289 "20:12",
290 "20:00",
291 "19:47",
292  
293 "19:34",
294 "19:21",
295 "19:08",
296 "18:54",
297 "18:40",
298  
299 "18:25",
300 ],
301  
302 "Aug"=>[
303 "18:10",
304 "17:55",
305 "17:40",
306 "17:24",
307 "17:08",
308  
309 "16:52",
310 "16:36",
311 "16:19",
312 "16:02",
313 "15:45",
314  
315 "15:27",
316 "15:10",
317 "14:52",
318 "14:33",
319 "14:15",
320  
321 "13:56",
322 "13:37",
323 "13:18",
324 "12:59",
325 "12:39",
326  
327 "12:19",
328 "11:59",
329 "11:39",
330 "11:19",
331 "10:58",
332  
333 "10:38",
334 "10:17",
335 "9:56",
336 "9:35",
337 "9:13",
338  
339 "8:52",
340 ],
341  
342 "Sep"=>[
343 "8:30",
344 "8:09",
345 "7:47",
346 "7:25",
347 "7:03",
348  
349 "6:40",
350 "6:18",
351 "5:56",
352 "5:33",
353 "5:10",
354  
355 "4:48",
356 "4:25",
357 "4:02",
358 "3:39",
359 "3:16",
360  
361 "2:53",
362 "2:30",
363 "2:06",
364 "1:43",
365 "1:20",
366  
367 "0:57",
368 "0:33",
369 "0:10",
370 "-0:14",
371 "-0:37",
372  
373 "-1:00",
374 "-1:24",
375 "-1:47",
376 "-2:10",
377 "-2:34",
378 ],
379  
380 "Oct"=>[
381 "-2:57",
382 "-3:20",
383 "-3:44",
384 "-4:07",
385 "-4:30",
386  
387 "-4:53",
388 "-5:16",
389 "-5:39",
390 "-6:02",
391 "-6:25",
392  
393 "-6:48",
394 "-7:10",
395 "-7:32",
396 "-7:35",
397 "-8:18",
398  
399 "-8:40",
400 "-9:02",
401 "-9:24",
402 "-9:45",
403 "-10:07",
404  
405 "-10:29",
406 "-10:50",
407 "-11:12",
408 "-11:33",
409 "-11:54",
410  
411 "-12:14",
412 "-12:35",
413 "-12:55",
414 "-13:15",
415 "-13:35",
416  
417 "-13:55",
418 ],
419  
420 "Nov"=>[
421 "-14:14",
422 "-14:34",
423 "-14:53",
424 "-15:11",
425 "-15:30",
426  
427 "-15:48",
428 "-16:06",
429 "-16:24",
430 "-16:41",
431 "-16:58",
432  
433 "-17:15",
434 "-17:32",
435 "-17:48",
436 "-18:04",
437 "-18:20",
438  
439 "-18:35",
440 "-18:50",
441 "-19:05",
442 "-19:19",
443 "-19:33",
444  
445 "-19:47",
446 "-20:00",
447 "-20:13",
448 "-20:26",
449 "-20:38",
450  
451 "-20:50",
452 "-21:01",
453 "-21:12",
454 "-21:23",
455 "-21:33",
456 ],
457  
458 "Dec"=>[
459 "-21:43",
460 "-21:52",
461 "-22:01",
462 "-22:10",
463 "-22:18",
464  
465 "-22:25",
466 "-22:32",
467 "-22:39",
468 "-22:46",
469 "-22:52",
470  
471 "-22:57",
472 "-23:02",
473 "-23:07",
474 "-23:11",
475 "-23:14",
476  
477 "-23:17",
478 "-23:20",
479 "-23:22",
480 "-23:24",
481 "-23:25",
482  
483 "-23:26",
484 "-23:26",
485 "-23:26",
486 "-23:26",
487 "-23:25",
488  
489 "-23:23",
490 "-23:21",
491 "-23:19",
492 "-23:16",
493 "-23:12",
494  
495 "-23:08",
496 ],
497 );
498 3 our @months=("Jan", "Feb", "Mar", "Apr", "May", "Jun",
499 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
500  
501  
502 =head3 declination($date, [ $units])
503  
504 Returns the declination of the sun on the given day of the year.
505  
506 =over
507  
508 =item $date
509  
510 A DateTime object. Only the day and month are relevant.
511  
512  
513 =item $units
514  
515 The units to return, either 'rad' or 'deg'.
516 This determines whether the result is returned as radians or
517 degrees. If you are going to pass the result to trigonometric
518 functions then radians are better. Default 'rad'.
519  
520 =back
521  
522 =cut
523  
524 0 ▶sub declination {
Subroutine declination: not called CC=7 SCAR=40.3
Pod documented
525 0 my $date = shift;
526 0 my $day = $date->day;
527 0 my $month = $date->month;
528 0 ▶ my $as = scalar @_ ? shift : "rad";
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ ? : 0 0 0
529 # Do some basic validation
530 0 ▶ if ($month !~ /^[a-z0-9]+$/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($month =~ /^[a-z0-9]+$/i) 0 0 0
531 0 print "Bad month: not alphanumeric: $month\n";
532 0 return undef;
533 }
534 0 ▶ if ($day !~ /^[0-9]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($day =~ /^[0-9]+$/) 0 0 0
535 0 print " (declination) Bad day: not numeric: $day\n";
536 0 return undef;
537 }
538 0 ▶ if ($month =~ /^[0-9]+$/){
Branch: 1 branch
BranchTrueFalseTotal
if ($month =~ /^[0-9]+$/) 0 0 0
539 0 $month = $months[$month-1];
540 }
541 0 $month = ucfirst(lc($month)); # Get the case right
542  
543 # Get the declination of the sun for this date.
544 0 my $decl = $Declination{$month}->[$day-1];
545 0 my ($deg, $min) = ($decl =~ /(-?[0-9]+):([0-9]+)/);
546 0 ▶ if ($deg < 0){ $min = -$min;}
Branch: 1 branch
BranchTrueFalseTotal
if ($deg < 0) 0 0 0
547 0 $deg += $min/60.0;
548  
549 0 ▶ if ($as eq "deg"){ return $deg;}
Branch: 1 branch
BranchTrueFalseTotal
if ($as eq "deg") 0 0 0
550 0 $decl = deg2rad($deg);
551 0 return $decl;
552 }
553 3 1;
554  
555  
556 =head1 AUTHOR
557  
558 Raphael Mankin, C<< <rapmankin at cpan.org> >>
559  
560 =head1 BUGS
561  
562 Please report any bugs or feature requests to C<bug-datetime-event-jewish at rt.cpan.org>, or through
563 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DateTime-Event-Jewish>. I will be notified, and then you'll
564 automatically be notified of progress on your bug as I make changes.
565  
566  
567  
568  
569 =head1 SUPPORT
570  
571 You can find documentation for this module with the perldoc command.
572  
573 perldoc DateTime::Event::Jewish
574  
575  
576 You can also look for information at:
577  
578 =over 4
579  
580 =item * RT: CPAN's request tracker
581  
582 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DateTime-Event-Jewish>
583  
584 =item * AnnoCPAN: Annotated CPAN documentation
585  
586 L<http://annocpan.org/dist/DateTime-Event-Jewish>
587  
588 =item * CPAN Ratings
589  
590 L<http://cpanratings.perl.org/d/DateTime-Event-Jewish>
591  
592 =item * Search CPAN
593  
594 L<http://search.cpan.org/dist/DateTime-Event-Jewish/>
595  
596 =back
597  
598  
599 =head1 ACKNOWLEDGEMENTS
600  
601  
602 =head1 LICENSE AND COPYRIGHT
603  
604 Copyright 2010 Raphael Mankin.
605  
606 This program is free software; you can redistribute it and/or modify it
607 under the terms of either: the GNU General Public License as published
608 by the Free Software Foundation; or the Artistic License.
609  
610 See http://dev.perl.org/licenses/ for more information.
611  
612  
613 =cut
614  
615 3 1; # End of DateTime::Event::Declination
« Jewish/Haversine.pm ↑ Summary Jewish/Parshah.pm »