Closed ravage84 closed 4 years ago
We have a number of comparison methods that would fall under 'solution 3' from that article. How do you see these precision methods being used?
// With methods
$now = Chronos::now();
$nowPreciseToHour = $now->setPrecisionToHour();
$someOtherDate = Chronos::create(2017, 12, 25, 4, 32, 58);
$otherDatePreciseToHour = $someOtherDate->setPrecisionToHour();
// With different types
$nowPreciseToHour = ChronosHour::now();
$otherDatePreciseToHour = ChronosHour:parse($someStringToParse);
Instead of working with one of the diffInXyz()
methods, you can compare apple with apple.
Eric Evans proposes an interesting solution to problems like this in this talk "Eploring Time": Allen's interval algebra
But a solution like the one proposed would probably go way too far and would likely be implemented on a programming language level at best.
After reading a recent article about time precision, I was wondering if it would make sense to include convenience functions for choosing/setting precision into Chronos?
I could imagine setting the precision of a date or datetime object to:
Creating two datetime objects, setting their precision and comparing them could become quite easy... Some of that might be possible already through one wary or another.
Alternatively, instead of functions, this could be implemented through different precision classes.
May be all this is just a brain fart. Let me know.