This is a DateTime::Incomplete API upgrade RFC,
based in ideas from Claus F�rber, Eugene van der Pijll and others:
$dtj = DateTime::Calendar::Julian->new(
year => 1970 );
$dtm = DateTime::Calendar::Mayan->new(
baktun => 0 );
$dtij = DateTime::Incomplete->new(
year => 1537,
base => $dtj );
# If 'base' supports 'year', and 'year' can be
# set to '1537', then you are ok. Otherwise it will die.
$dtim = DateTime::Incomplete->new(
kin => 8,
base => $dtm );
print $dtij->has( 'month' );
# 0
print $dtim->has( 'kin' );
# 1
print $dtim->get( 'kin' );
# 8
print $dtim->fields;
# kin 8
print $dtim->base_class;
# DateTime::Calendar::Mayan
Additional specifications:
Default 'base' is DateTime->new( year => 1970 );
You can get a 'normal' DateTime by calling
$dtj2 = $dtij->to_datetime;
$dtj2 = $dtij->to_datetime( base => $other_julian_base );
$dtm2 = $dtim->to_datetime( base => $other_mayan_base );
$dtim->set_base( $other_mayan_base );
$dtm2 = $dtim->to_datetime;
DateTime::Incomplete does not replicate the full DateTime API.
Additional methods can be implemented by subclassing
DateTime::Incomplete.
Only some DateTime accessors are implemented, such as
year, month, etc, and simple stringification.
Dave Rolsky said:
> This may require some tweaks to DateTime.pm but that's probably ok.
I'd like to have this in DateTime:
set( time_zone => $tz );
set( locale => $loc );
get( time_zone/locale/year/month/etc );
# returns a number or an object
get_str( time_zone/locale/year/month/etc );
# returns a formatted number or a name
and maybe:
can_set; # returns qw/time_zone locale year month etc/
can_get; # returns qw/time_zone locale year month week etc/
- Flavio S. Glock