On Tue, 14 Jan 2003, Matthew Simon Cavalletto wrote:

> >   use DateTime::Parse::MySQL; # this needs a better name
>
> I've suggested "DateTime::Format::MySQL".

Actually, I'm leaning towards DateTime::Representation::* at the moment.
Format is correct if read as a noun, but confusing if read as a verb.

> >   print DateTime::Parse::MySQL->mysql_datetime( $dt );
>
> There should be no need to repeat the word "mysql" in the method name,
> since the package name clearly disambiguates that.

That's true.

> So, here's the option I'm proposing:
>
>    use DateTime;
>    use DateTime::Format::MySQL;
>    my $dt = DateTime::Format::MySQL->new_datetime( $mysql_dt );
>    print DateTime::Format::MySQL->format_string( $dt );

MySQL has quite a number of possible formats, including:

  DATETIME column - "YYYY-MM-DD HH:MM:SS"
  DATE column     - "YYYY-MM-DD"
  TIME column     - "HH:MM::S"
  TIMESPAN column - "YYYYMMDDHHMMSS" and about 6-7 others

So the method names will have to distinguish between these.

It's possible to simply offer one method per data type.  See
Time::Piece::MySQL for an example of how this is done.  That seems like a
reasonable breakdown in this case.  But the point is there _must_ be more
than one method for formatting, though in theory parsing could be done
with just one method

I don't actually like having parsing done with one method, because it
encourages user mistakes like passing in just a date, but thinking you
have a datetime.  Then you're confused as to why the time is always
"00:00:00".

> I'm also proposing the addition of gateway methods where appropriate;
> these are just dynamic dispatch methods for convenience, hopefully only
> a few lines of code each.
>
>    my $dt = DateTime->new_from_format( 'MySQL', $mysql_dt );
>    print $dt->format_string( 'MySQL' );
>
> It seems to me that this effectively combines the best features of the
> two existing proposals -- each set of parser/formatter goes into a
> separate namespace and a polymorphic API, *AND* there's an interface
> directly accessible from the DT objects themselves

Make a proposal that handles multiple formats per module, and I'll
consider it.  Obviously, what you propose above doesn't work without some
sort of extension.


-dave

/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/

Reply via email to