At 9:29 AM -1000 11/6/03, Joshua Hoblitt wrote:
I'm willing to concede that DT::Duration can be left alone but I really think that millisecond and microsecond support would be useful for DT. In fact I think it would be consistent with the rest of the API as you don't have to specify a year as 365 days either. While I know that a millisecond needs to be multiplied by 10**6 to convert it nanoseconds I don't think that qualifies as "common knowledge".

<DISCLAIMER>
The following is tacked on as a reply to Joshua's post, but that it just to give it context. This in no way is a personal attack on him or anyone else who has talked about sub-second accessors and constructors, but rather on the whole idea in general.
</DISCLAIMER>




Datetimers,

I can understand why we look like we need all this stuff for milli-, micro- and nano-seconds, but it is exactly what I was scared of when we were talking about sub-second support. Nano-, Milli- and Micro- seconds are not different things like hours an minutes are, they're just fractional seconds. We really should have just left it as floating seconds, or as fractional seconds rather than settling on some arbitrary precision like nanoseconds.

If we allow a constructor for nano-, micro- and milli- then maybe we should allow one for decaminutes? The same with accessors. They're just descriptions of the same thing: fractions. A millisecond is 1/1000 seconds, a decaminute is 10/1 minutes.

You can represent time with accessors like: ->hour:->minute:->second, but accessors like micro- and milli- are ambiguous. They look like the other accessors so can you just 'whack them on'?

$dt->hour . ':' . $ct->minute . ':' . $st->second . '.' . $dt->millisecond . $dt->microsecond . $dt->nanosecond

I doubt it. You'll have to pick your precision and only use that.

We really should have just left it as ->second and ->fractional_second and probably ->floating_second($precision) (returning floating, not fractional seconds). We especially don't need them in the constructor. It's confusing now:

$dt = DateTime->new(%date, second=>12, nanosecond=>345)

Is that 12.345 seconds? Nup. It's 12.000000345 (I think).

$dt = DateTime->new(%date, second=>12, fractional_second=>345)

Is that 12.345 seconds? Nup. It's 357 seconds!

Imagine extra constructors, it feels good at first:

$dt = DateTime->new(
        year=>2003,
        month=>6,
        day=>12,
        hour=>7,
        minute=>22,
        second=>12,
        millisecond=>345,
        microsecond=>678,
        nanosecond=>901
);

However, the accessors don't 'behave' themselves:

$dt->year == 2003 .. yup
$dt->month == 6 .. yup
$dt->day == 12 .. yup
$dt->hour == 7 .. yup
$dt->minute == 22 .. yup
$dt->second == 12 .. yup
$dt->millisecond == 347 .. oops
$dt->microsecond == 345678 .. hang on, where did all that come from, we constructed it with just '678'
$dt->nanosecond == 345678901 .. same here, it used to be just '901'


Of course you could have extra accessors for ->just_nanoseconods (returns 901), ->just_microseconds and ->just_milliseconds, but it's all a little silly. Can't we can the nanosecond and just talk about seconds (and fractional seconds)?

Cheers!
Rick




-- -------------------------------------------------------- There are 10 kinds of people: those that understand binary, and those that don't. -------------------------------------------------------- The day Microsoft makes something that doesn't suck is the day they start selling vacuum cleaners -------------------------------------------------------- "Write a wise proverb and your name will live forever." -- Anonymous --------------------------------------------------------

Reply via email to