Welcome to the Monastery | |
PerlMonks |
DateTime::Span intersection inconsistenciesby mikeman (Acolyte) |
on Jun 30, 2011 at 12:39 UTC ( [id://912176]=perlquestion: print w/replies, xml ) | Need Help?? |
mikeman has asked for the wisdom of the Perl Monks concerning the following question: When using DateTime::Span->intersects to check for intersections, the spans produced by DateTime::Span->from_datetime_and_duration, and those produced by DateTime::Span->from_datetimes, give what appear to be inconsistent results:
Here are the test results:
Note: subtracting one nanosecond from $dt2 in the failing test causes it to succeed:
It therefore looks as though one nanosecond is going missing somewhere. Is this intentional -- am I missing something to do with DateTime::Duration objects, or is this down to a bug in one of the DateTime modules? I'm using DateTime version 0.70 and DateTime::Span version 0.30 (the latest versions at the time of writing). Update: After quite a lot of digging, I discovered that the new end of set created by DateTime::Span->from_datetime_and_duration is open by default -- it is a semi-open set with a start and open end. The end is therefore before the time+duration (by one nanosecond). That explains why the intersection is false. The fact that the end of the set is open is stated in the docs, but I had not understood its ramifications. I'm still not clear on why the end of the set defaults to being open, but at least I can work around the issue I had.
Back to
Seekers of Perl Wisdom
|
|