On Mon, Jun 09, 2003 at 03:32:39PM -1000, Joshua Hoblitt wrote:
> > But never-the-less the website could really do with a 'Migration' section.
> > I'll volunteer to do the initial write and everyone can have CVS access to
> > keep it up-to-date.
> 
> Sounds good - I was hoping someone else would volunteer. :)  Here's two more 
> conversions I posted to the list months ago.

> print "Compare dates\n";
> cmpthese( -5, {
>       DateTime => sub {
>               my $dt1 = DateTime->now();
>               $dt1->set_time_zone( '-1000' );
>               my $dt2 = DateTime::Format::MySQL->parse_datetime( "2000-05-10 
> 15:15:00" );
>               my $dt_dur = DateTime::Duration->new( days => 4 );
>               $dt1->subtract_duration( $dt_dur );
>               my $cmp = DateTime->compare($dt1, $dt2);
>       },
>       'Date::Manip' => sub {
>               my $dm1 = Date::Manip::DateCalc( "now", "- 4 days" );
>               my $dm2 = Date::Manip::ParseDate( "2000-05-10 15:15:00" );
>               my $cmp = Date::Manip::Date_Cmp( $dm1, $dm2 );
>       },
> });

FAQ answers should answer more questions then they generate,
but two obvious questions leap out of that code...

1. Why is set_time_zone() needed for this DateTime example?

2. Why use DateTime::Format::*MySQL* when the code may have nothing
   to do with MySQL, it just happens to use the same, very common, format?

I do think there should be a DateTime::Format::Common with a
parse_datetime() that can handle common _unambiguous_ numeric formats.

A single regex could handle all formats that follow the ISO 8601
general left-to-right decreasing resolution style, with assorted
optional punctuation, plus optional appended TZ.

Tim.

Reply via email to