On Jan 8, 2006, at 4:13 PM, Rick Measham wrote:

David Wheeler wrote:
The normalization stuff in DateTime::Format::Duration gets us part of the way there, but not quite, as if I say, "23 hours, 90 minutes", it will return "24 hours 29 minutes", which is not quite the same as what was initially specified.

That's probably as close as you can get ..

Yeah...

I'd be thinking of just storing the values as a hash(ref) that you later feed back into DT:D when you need to. That way you can store it however you need to.

That's what I was most of the way through a patch to implement. I've attached it FYI; you guys can do with it what you will. All tests pass, and it should be right, but I hadn't yet added any new tests to see if the "norm" values were always right. And I hadn't yet documented the new norm_deltas() method (not sure that "norm" is the best way to describe this feature, though).

(Personally, I'd be happy as a user if I asked for 90m if it returned 1h30m .. but I imagine different things need different units)

An do you know what? That's exactly what the bloody in_units() method does. And maybe that's just good enough!

  use aliased 'DateTime::Duration';
  my $du = Duration->new( minutes => 90 );
  print join(', ', $du->in_units(qw(hours minutes))), $/; # "1, 30"

So I'll just go with that.

Best,

David

Attachment: norm.patch
Description: Binary data

Reply via email to