DateConvert
view release on metacpan or search on metacpan
$days %= $NORMAL_YEAR;
$days += 1; # today
$year += 1;
} else {
$year += int ($days / $NORMAL_YEAR + 1) - 1;
$days = $LEAP_YEAR;
}
$$self{year}=$year;
$$self{days_into_year}=$days;
return $year;
}
sub is_leap {
my $self = shift;
my $year = shift || $self->year; # so is_leap can be static or method
return 0 if ($year %4);
return 1;
}
# OK, we're done. Everything else just gets inherited from Gregorian.
1;
__END__
=head1 NAME
Date::Convert - Convert Between any two Calendrical Formats
=head1 SYNOPSIS
use Date::DateCalc;
$date=new Date::Convert::Gregorian(1997, 11, 27);
@date=$date->date;
convert Date::Convert::Hebrew $date;
print $date->date_string, "\n";
Currently defined subclasses:
Date::Convert::Absolute
Date::Convert::Gregorian
Date::Convert::Hebrew
Date::Convert::Julian
Date::Convert is intended to allow you to convert back and forth between
any arbitrary date formats (ie. pick any from: Gregorian, Julian, Hebrew,
Absolute, and any others that get added on). It does this by having a
separate subclass for each format, and requiring each class to provide
standardized methods for converting to and from the date format of the base
class. In this way, instead of having to code a conversion routine for
going between and two arbitrary formats foo and bar, the function only
needs to convert foo to the base class and the base class to bar. Ie:
Gregorian <--> Base class <--> Hebrew
The base class includes a B<Convert> method to do this transparently.
Nothing is exported because it wouldn't make any sense to export. :)
=head1 DESCRIPTION
Fucntion can be split into several categories:
=over 4
=item *
Universal functions available for all subclasses (ie. all formats). The
fundamental conversion routines fit this category.
=item *
Functions that are useful but don't necessarily make sense for all
subclasses. The overwhelming majority of functions fall into this
category. Even such seemingly universal concepts as year, for instance,
don't apply to all date formats.
=item *
Private functions that are required of all subclasses, ie. B<initialize>.
These should I<not> be called by users.
=back
Here's the breakdown by category:
=head2 Functions Defined for all Subclasses
=over 4
=item new
Create a new object in the specified format with the specified start
paramaters, ie. C<$date = new Date::Convert::Gregorian(1974, 11, 27)>. The
start parameters vary with the subclass. My personal preference is to
order in decreasing order of generality (ie. year first, then month, then
day, or year then week, etc.)
This can have a default date, which should probably be "today".
=item date
Extract the date in a format appropriate for the subclass. Preferably this
should match the format used with B<new>, so
(new date::Convert::SomeClass(@a))->date;
should be an identity function on @a if @a was in a legitmate format.
=item date_string
Return the date in a pretty format.
=item convert
( run in 1.441 second using v1.01-cache-2.11-cpan-39bf76dae61 )