On Wed, 15 Sep 2004 22:56:10 -0700, Mark D. Anderson wrote
> I have a database table with a column containing iso 8601 date strings.
> Not all of these values have the same precision: some are accurate only
> to the year, some to the day, and some to the hour and minute.

Have a look at DateTime::Incomplete.

use DateTime::Incomplete;
foreach (qw/2004 2004-08 2004-09-16/) {
    my ($year, $month, $day) = split/-/;
    $dti = DateTime::Incomplete->new(
        year  => $year  || undef,
        month => $month || undef,
        day   => $day   || undef,
    );
    if ($dti->has_day) {
        
    } elsif ($dti->has_month) {

    } elsif ($dti->has_year) {

    }
}
__END__

Of course, DateTime::Format::ISO8601 still sets a default if you use it to 
parse the datetime. (Joshua: You accept a DateTime object for filling in 
missing parts; is there any chance you could also accept a 
DateTime::Incomplete object? If such an object is supplied, your parser would 
return a DT:I object)

Cheers!
Rick Measham




Reply via email to