-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Labels
Milestone
Description
Following discussion in #495, this is a tracking issue for breaking changes to consider for 4.x.
Proposed Changes
Return ChronosInterval from Chronos::diff()
Currently Chronos::diff() returns a native DateInterval. In 4.x, it should return ChronosInterval instead to provide:
- ISO 8601 duration formatting via
__toString() - Convenience methods like
totalSeconds(),totalDays(),isZero(),isNegative() - Arithmetic methods
add(),sub() toDateString()for strtotime-compatible outputtoNative()for backwards compatibility when aDateIntervalis needed
Migration Path
Users who need a DateInterval can call ->toNative() on the result:
// Before (3.x)
$interval = $date1->diff($date2);
// After (4.x) - if DateInterval is needed
$interval = $date1->diff($date2)->toNative();
// After (4.x) - using new features
$interval = $date1->diff($date2);
echo $interval; // "P1Y2M3D"
echo $interval->totalDays();References
- Add ChronosInterval class #495 - ChronosInterval implementation
- ChronosInterval #444 - Original discussion
Reactions are currently unavailable