On Wed, 11 Jan 2006, Heiko Klein wrote:

For a couple of years, I have had a problem in correctly handling timespans on computers in (human) common-sense. I'm currently switching my time-handling functions to DateTime and hoped it would solve this problem too, but it doesn't:

When talking to somebody, I would say: I'm away from 2006-01-01 to 2006-01-10 and everybody will now: I won't come back before 2006-01-11. Putting this into DateTime::Span :

Actually, if you say "to 2006-01-10" I'd find it ambiguous. If you said "through 2006-01-10" it'd be clearer.

-----
$dt1 = DateTime->new(year => 2006, month => 1, day => 1);
$dt2 = DateTime->new(year => 2006, month => 1, day => 10);

$span = DateTime::Span->from_datetimes( start => $dt1, end => $dt2 );

I think this pretty clear, but I think what you _really_ want is this:

  DateTime::Span->from_datetimes( start => $dt1, before => $dt2->add( days => 1 
) );

The "before" means up to but not including the end point. The docs need some more clarity on this point.

Wouldn't it be possible to add an internal flag to DateTime, saying something about the level of accuracy, i.e. '_truncated_to' with possible values (year, month, day, hour, min, sec, ms), so that a comparison would only compare up to this level, instead of adding 0 to the values not given.

It should give $dt2 == $dt3, since comparing only to day.

This'd be possible, but I fear complicating the API even more. What might be useful would be date-only objects, maybe as DateTime::Date or something like that.


-dave

/*===================================================
VegGuide.Org                        www.BookIRead.com
Your guide to all that's veg.       My book blog
===================================================*/

Reply via email to