`modify` is not 100% identical to the version from DateTimeImmutable
christian-kolb opened this issue · 3 comments
Describe the bug
The following doesn't do anything, but should move the datetime to the next saturday of the internal timezone.
$nextSaturday = DateTime::fromString('2022-10-25 15:00:00')->modify('next Saturday');
echo $nextSaturday->format('Y-m-d');
should be 2022-10-27
but results in 2022-10-25
.
Expected behavior
modify
should be identical to the implementation of \DateTimeImmutable
.
Additional context
A possible solution would be to internally just call self::fromDateTime($this->toDateTimeImmutable()->modify($modifier))
instead of a custom implementation.
But I don't know if there is a reason for not using a custom logic. Is there?
This is the reason why using the default modify method did not work for me.
I believe the fix is to check if in $dateTimeParts
there is a weekday
, calculate the delta and adjust the outcome.
Yeah I also realized that there is an unintuitive logic within the DateTimeImmutable
. Things like 2022-03-30
- 1 month is 2022-03-02
🤦
resolved by #304