Date-SundayLetter
view release on metacpan or search on metacpan
lib/Date/SundayLetter.pm view on Meta::CPAN
Rich Bowen
CPAN ID: RBOW
rbowen@rcbowen.com
http://www.rcbowen.com
=head1 COPYRIGHT
Copyright (c) 2001 Rich Bowen. All rights reserved.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
=head1 SEE ALSO
perl(1).
Date::ICal
Reefknot (http://reefknot.org/)
Date::Easter
Date::Passover
Date::Leapyear
=cut
# }}}
# sub sundayletter {{{
sub letter { return sundayletters(@_) }
sub sundayletters {
my $year = shift;
my @letters = qw(A G F E D C B);
my $p = parameter($year);
my $q = int($year / 4); # divide by 4, discard remainder
my $t = $year + $q + $p; # Add quotient to year, and add
# the parameter.
my $d = $t % 7; # Remainder when divided by 7 gives the
# displacement from January 1 to the first Sunday
# of the year.
my $letter;
if (Date::Leapyear::isleap( $year )) {
$letter = $letters[$d-1] . $letters[$d] ;
} else {
$letter = $letters[$d];
}
return $letter;
} #}}}
# sub parameter {{{
sub parameter {
# The "parameter" is a magic number that tracks how far the Gregorian
# calendar is from the Julian calendar. It has roughly to do with the
# fact that the Gregorian calendar observes leap year on the 4-century
# mark, and the Julian calendar does not.
my $year = shift;
my $S = int ($year / 100 );
my $P = ( int( $S/4 ) - $S ) % 7;
return $P;
} # }}}
1;
( run in 1.195 second using v1.01-cache-2.11-cpan-5a3173703d6 )