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 output
toNative() for backwards compatibility when a DateInterval is 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
Following discussion in #495, this is a tracking issue for breaking changes to consider for 4.x.
Proposed Changes
Return
ChronosIntervalfromChronos::diff()Currently
Chronos::diff()returns a nativeDateInterval. In 4.x, it should returnChronosIntervalinstead to provide:__toString()totalSeconds(),totalDays(),isZero(),isNegative()add(),sub()toDateString()for strtotime-compatible outputtoNative()for backwards compatibility when aDateIntervalis neededMigration Path
Users who need a
DateIntervalcan call->toNative()on the result:References