| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #$Header: /cvsroot/date-passover/lib/Date/Passover.pm,v 1.10 2002/08/30 00:06:51 rbowen Exp $ | 
| 2 |  |  |  |  |  |  | package Date::Passover; | 
| 3 | 2 |  |  | 2 |  | 34490 | use Date::GoldenNumber; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 145 |  | 
| 4 | 2 |  |  | 2 |  | 933 | use Date::DayOfWeek; | 
|  | 2 |  |  |  |  | 3013 |  | 
|  | 2 |  |  |  |  | 115 |  | 
| 5 | 2 |  |  | 2 |  | 1019 | use Date::ICal; | 
|  | 2 |  |  |  |  | 21748 |  | 
|  | 2 |  |  |  |  | 72 |  | 
| 6 | 2 |  |  | 2 |  | 16 | use Carp; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 132 |  | 
| 7 | 2 |  |  | 2 |  | 29 | use strict; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 69 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | BEGIN { | 
| 10 | 2 |  |  | 2 |  | 8 | use Exporter (); | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 32 |  | 
| 11 | 2 |  |  | 2 |  | 6 | use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 187 |  | 
| 12 | 2 |  |  | 2 |  | 3 | $VERSION     = (qw'$Revision: 1.12 $')[1]; | 
| 13 | 2 |  |  |  |  | 24 | @ISA         = qw (Exporter); | 
| 14 | 2 |  |  |  |  | 4 | @EXPORT      = qw (passover roshhashanah); | 
| 15 | 2 |  |  |  |  | 2 | @EXPORT_OK   = qw (); | 
| 16 | 2 |  |  |  |  | 647 | %EXPORT_TAGS = (); | 
| 17 |  |  |  |  |  |  | } | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | =head1 NAME | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | Date::Passover - When is Passover? When is Rosh Hashanah? | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | use Date::Passover; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | ($month, $day ) = roshhashanah( 1997 ); | 
| 28 |  |  |  |  |  |  | $date_ical_obj = roshhashahah( 1997 ); | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | ( $month, $day ) = passover( 1997 ); | 
| 31 |  |  |  |  |  |  | $date_ical_obj = passover( 1997 ); | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | Calculate the date of Passover or Rosh Hashanah for any given year. | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =head1 BUGS | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | None yet, but I expect I'll take care of that pretty soon. | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | =head1 SUPPORT | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | Email the author, or post to the datetime@perl.org mailing list. | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | =head1 AUTHOR | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | Rich Bowen | 
| 48 |  |  |  |  |  |  | CPAN ID: RBOW | 
| 49 |  |  |  |  |  |  | rbowen@rcbowen.com | 
| 50 |  |  |  |  |  |  | http://www.rcbowen.com | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | Copyright (c) 2001 Rich Bowen. All rights reserved. | 
| 55 |  |  |  |  |  |  | This program is free software; you can redistribute | 
| 56 |  |  |  |  |  |  | it and/or modify it under the same terms as Perl itself. | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | The full text of the license can be found in the | 
| 59 |  |  |  |  |  |  | LICENSE file included with this module. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | perl(1) | 
| 64 |  |  |  |  |  |  | Date::ICal | 
| 65 |  |  |  |  |  |  | Date::Easter | 
| 66 |  |  |  |  |  |  | Reefknot ( http://reefknot.org/ ) | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =cut | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub passover { | 
| 71 | 1 |  |  | 1 | 0 | 6 | my $year = shift; | 
| 72 | 1 |  |  |  |  | 3 | my $date = roshhashanah($year); | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 1 |  |  |  |  | 158 | my $m; | 
| 75 | 1 | 50 |  |  |  | 4 | if ($date->month == 9) { | 
| 76 | 1 |  |  |  |  | 24 | $m = $date->day; | 
| 77 |  |  |  |  |  |  | } else { | 
| 78 | 0 |  |  |  |  | 0 | $m = 30 + $date->day; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 1 |  |  |  |  | 13 | my $passover = Date::ICal->new( month=>3, day=>21, year =>$year ); | 
| 82 | 1 |  |  |  |  | 58 | $passover ->add( day => $m ); | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  |  | 
| 85 | 1 | 50 |  |  |  | 16 | if (wantarray) { | 
| 86 | 1 |  |  |  |  | 3 | return ($passover->month, $passover->day); | 
| 87 |  |  |  |  |  |  | } else { | 
| 88 | 0 |  |  |  |  | 0 | return $passover; | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | sub roshhashanah{ | 
| 93 | 7 |  |  | 7 | 0 | 1995 | my $year = shift; | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | # For the moment, we are limited to 1900 - 2099 | 
| 96 | 7 | 50 | 33 |  |  | 39 | if ( $year < 1900 || $year > 2099 ) { | 
| 97 | 0 |  |  |  |  | 0 | carp "Can't calculate Rosh Hashanah for dates before 1900 or | 
| 98 |  |  |  |  |  |  | after 2099. Please check back in a version or two"; | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 | 7 |  |  |  |  | 18 | my $g = golden( $year ); | 
| 102 | 7 |  |  |  |  | 10 | my $y = $year - 1900; | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 7 |  |  |  |  | 23 | my $day = 6.057778996 + 1.554241797*((12 * $g )%19) + 0.25*($y%4) | 
| 105 |  |  |  |  |  |  | - 0.003177794*$y; | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | # Do we have to postpone? | 
| 108 |  |  |  |  |  |  | # Warning: Many magic numbers | 
| 109 | 7 |  |  |  |  | 17 | my $dow = dayofweek( $day, 9, $year ); | 
| 110 | 7 | 100 | 66 |  |  | 237 | if ( $dow == 0 || $dow == 3 || $dow == 5 ) { | 
|  |  | 100 | 100 |  |  |  |  | 
|  |  | 50 | 66 |  |  |  |  | 
|  |  |  | 66 |  |  |  |  | 
|  |  |  | 33 |  |  |  |  | 
|  |  |  | 33 |  |  |  |  | 
| 111 | 3 |  |  |  |  | 5 | $day ++; | 
| 112 |  |  |  |  |  |  | } elsif ( ( $dow == 1 ) && ( ($day - (int($day))) >= 23269/25920 ) | 
| 113 |  |  |  |  |  |  | && ( ( (12 * $g )%19 ) > 11 ) ) { | 
| 114 | 1 |  |  |  |  | 20 | $day ++; | 
| 115 |  |  |  |  |  |  | } elsif ( ( $dow == 2 ) && ( $day - (int($day)) >= 1367/2160 ) | 
| 116 |  |  |  |  |  |  | && ( ( (12*$g) % 19) > 6 )) { | 
| 117 | 0 |  |  |  |  | 0 | $day += 2; | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  |  | 
| 120 | 7 |  |  |  |  | 7 | $day = int($day); | 
| 121 | 7 |  |  |  |  | 5 | my $month = 9; | 
| 122 | 7 | 100 |  |  |  | 15 | if ( $day > 30 ) { | 
| 123 | 3 |  |  |  |  | 3 | $day -= 30; | 
| 124 | 3 |  |  |  |  | 4 | $month++; | 
| 125 |  |  |  |  |  |  | } | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 7 | 100 |  |  |  | 24 | if (wantarray) { | 
| 128 | 6 |  |  |  |  | 13 | return ( $month, int($day) ); | 
| 129 |  |  |  |  |  |  | } else { | 
| 130 | 1 |  |  |  |  | 9 | return Date::ICal->new( month => $month, day => $day, year => | 
| 131 |  |  |  |  |  |  | $year); | 
| 132 |  |  |  |  |  |  | } | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | 1; | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  |  |