develooper Front page | perl.datetime | Postings from January 2006

DateTime::Span, enddate and common-sense vs computers

Thread Next
From:
Heiko Klein
Date:
January 11, 2006 04:39
Subject:
DateTime::Span, enddate and common-sense vs computers
Message ID:
43C4FC65.6000606@gmx.net
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 :

-----
$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 );

$dt3 = DateTime->new(year => 2006, month => 1, day => 10, hour => 22, 
minute => 1, second => 5);

$span->contains($dt3); # this returns wrong
-----

The problem is obvious and could be covered by truncate, but I think, 
truncate is a problem, too, since I need to know where to truncate.



Just an idea:

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.


I haven't had a look at the source to see if it is possible. I'm just 
testing how much DateTime can help me. It does already a lot.

Best regards,

Heiko

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About