On Thu, 5 Aug 2004, Ofer Nave wrote:
> 1) Why have different 'new' and 'from_epoch' constructors? Couldn't one
> always use 'new' and have the module figure out what information to
> initiatlize itself with by seeing if either the 'year' or 'epoch' name
> parameter was passed? I think it would provide a cleaner and more
> consistent interface.
>
> Instead of:
>
> my $date1 = DateTime->new( year => 2003
> month => 1,
> day => 1,
> );
> my $date2 = DateTime->from_epoch( epoch => time() );
>
> You could do this:
>
> my $date1 = DateTime->new( year => 2003
> month => 1,
> day => 1,
> );
> my $date2 = DateTime->new( epoch => time() );
I don't like APIs which can lead to someone confusing themself. With what
you suggest, I guarantee someone'd do this:
DateTime->new( epoch => time(), year => 2001 )
and either ask why it doesn't work, or get annoyed at the resulting error.
Plus then we'd have docs saying "you can pass _either_ X and Y, or Y and
Z, or X and Z". ETOOCONFUSING!
> 2) However, if you continue to provide different constructors, then when
> using from_epoch, why require the 'epoch' named paramter? Why not assume a
> single argument is an epoch value?
>
> Instead of:
>
> my $date = DateTime->from_epoch( epoch => time() );
>
> You could do this:
>
> my $date = DateTime->from_epoch( time() );
Because you can still pass time_zone and locale parameters to this method.
> 3) I copied the following code from the Strptime example in Section 2.7 of
> the FAQ:
>
> Instead of:
>
> # prints '2003-05-04 12:55:10';
> print $dt->ymd . ' ' . $dt->hms;
>
> You could offer one or more of these:
>
> # prints '2003-05-04 12:55:10';
> print $dt->ymd_hms;
> print $dt->ymdhms;
> # prints '2003-05-04 12:55:10.123456789';
> print $dt->ymdhmsn;
There is a datetime method that returns the ISO8601 formatted date. The
problem with what you suggest is that we then need to allow up to four
separators (date components, date from time, time components, time from
nanoseconds), which starts getting a bit hairy. I think $dt->ymd('/')
relatively obvious, but $dt->ymdhmsn('/', 'T', ':', ',') is not so clear
;)
> 4) From section 6.13: "How do I find yesterday's Date?"
>
> Instead of:
>
> my $dt = DateTime->now()->subtract( days => 1 );
>
> Why not add the two most popular uses as convenience functions:
>
> my $dt = DateTime->yesterday();
> my $dt = DateTime->tomorrow();
>
> This would be especially useful in business environments where half of the
> code that runs daily runs to process the previous day's data (like web
> logs), and so yesterday's date is often the first thing calculated in a
> script.
That's a possibility, although there are _so_ many methods right now I'm
leary of adding more. OTOH, these are super easy to document.
-dave
/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/