Calendar-Any
view release on metacpan or search on metacpan
lib/Calendar/Any/Julian.pm view on Meta::CPAN
}
#==========================================================
# Private functions
#==========================================================
sub _absoulte_date {
my ($month, $day, $year) = @_;
int(_day_of_year($month, $day, $year) + 365*($year-1) + ($year-1)/4 -2);
}
sub _day_of_year {
use integer;
my ($month, $day, $year) = @_;
my $day_of_year = $day + 31 * ($month-1);
if ( $month > 2) {
$day_of_year -= (23 + 4*$month)/10;
if ( _is_leap_year($year) ) {
$day_of_year++;
}
}
return $day_of_year;
}
sub _is_leap_year {
my $year = shift;
if ( $year < 0 ) {
$year = abs($year) - 1;
}
$year % 4 == 0
}
sub _last_day_of_month {
my ($month, $year) = @_;
return unless $month>0 && $month<13;
if ( $month==2 && _is_leap_year($year) ) {
29;
} else {
$MONTH_DAYS[$month]-$MONTH_DAYS[$month-1];
}
}
1;
__END__
=head1 NAME
Calendar::Any::Julian - Perl extension for Julian Calendar
=head1 VERSION
version 0.5
=head1 SYNOPSIS
use Calendar::Any::Julian;
my $date = Calendar::Any::Julian->new(1, 1, 2006);
=head1 DESCRIPTION
From "FREQUENTLY ASKED QUESTIONS ABOUT CALENDARS"(C<http://www.tondering.dk/claus/calendar.html>)
=over
The Julian calendar was introduced by Julius Caesar in 45 BC. It was
in common use until the late 1500s, when countries started changing to
the Gregorian calendar (section 2.2). However, some countries (for
example, Greece and Russia) used it into the early 1900s, and the
Orthodox church in Russia still uses it, as do some other Orthodox
churches.
In the Julian calendar, the tropical year is approximated as 365 1/4
days = 365.25 days. This gives an error of 1 day in approximately 128
years.
The approximation 365 1/4 is achieved by having 1 leap year every 4
years.
=back
=head1 METHOD
=over 4
=item is_leap_year
True if the date in a leap year.
=item day_of_year
Return the day of year the day of the year, in the range 1..365 (or
1..366 in leap years.)
=item last_day_of_month
Return the last day in the month. For example:
$date = Calendar::Any::Julian->new(2, 1, 2006);
print $date->last_day_of_month; # output 28
=back
=head1 AUTHOR
Ye Wenbin <wenbinye@gmail.com>
=head1 SEE ALSO
L<Calendar::Any>, L<Calendar::Any::Gregorian>
=cut
( run in 0.959 second using v1.01-cache-2.11-cpan-85f18b9d64f )