Also, maybe DateTime should throw some kind of error when you run in_units and a higher partition is being stripped off?

Ex:
my $dur = DateTime::Duration->new(months => 3, days=> 4);
$dur->in_units(days);  # Error; currently 4
$dur->in_units(years); # No error, 0.

It's not an error, and warnings for this sort of stuff will just annoy people.

I think this your average newcomer will find this very confusing!

# From the POD
my $dur = DateTime::Duration->new( years => 1, months => 15 );

$dur->in_units( ’years’ );            # 2
$dur->in_units( ’months’ );           # 27
$dur->in_units('days');        # 0

- or another one -

(DateTime->now - DateTime->today)->in_units('hours'); # 9 How many hours between now and midnight?
(DateTime->now - DateTime->today)->in_units('minutes'); # 591 How many minutes between now and midnight?
(DateTime->now - DateTime->today)->in_units('seconds'); # 34 How many seconds between now and midnight?


I think that a method like this should do what you expect it to do, and if it can't do that, then return an error. This is one of those cases where instead of returning an error, it returns an unexpected result. Very few people new to DateTime would expect this behavior. Or if they planned for that sort of result, they would have called delta_*.

<imho>
DateTime does a great job of staying accurate during all sorts of calendrical calculations. Sometimes, however, I feel like it makes really common tasks cumbersome in favor remaining calendrically correct. This, IMHO, will probably keep DateTime from replacing the other modules & becoming the standard time module for perl. That's a shame, because other than a few little nuances it's really an excellent (and very complete) set of modules.


Ex:
- DateTime->now returns UTC
- There's no way to set a default timezone
- DateTime::Duration should be the so called "stopwatch duration"

I'm sure there are others, but those are the ones that I run into most commonly.
</imho>


Finally, I think some explanation should be added to DT:Duration::in_units that explains all of this!

I'll add it. The conversion issues are explained in DateTime.pm at length and mentioned in the DESCRIPTION section of DT::Duration, but not in the in_units method.

Yeah, I remembered reading that somewhere - so just a pointer then would be fine. thanks.


- Max

Reply via email to