Fix #61642: modify("+5 weekdays") returns Sunday#122
Conversation
|
After applying this patch, today on July 14 I get: ./cliphp -r '$d = new datetime(); var_dump($d->modify("+5 weekdays"));' and this: ./cliphp -r '$d = new datetime(); var_dump($d->modify("+6 weekdays"));' Looks like something is wrong - +5 weekdays and +6 weekdays should not return the same result. |
|
I'd recommend also adding more numbers - maybe from -10 to +10 - to the test, just to be sure. |
Adding a non-zero multiple of 5 weekdays to any Friday, Saturday, or Sunday would result in a Sunday instead of the correct date. This patch provides an implementation of do_adjust_special_weekday() which does not suffer from this issue.
|
I had based my implementation on the bug report, and made it work exactly as the "Expected" section for +5 weekdays. I also used the existing +0/+1 semantics for weekends, which caused e.g. Saturday +0 weekdays and Saturday +1 weekday to both result in the following Monday. I've given it some more thought and I realized you're right that adding 5 and 6 weekdays to a Saturday shouldn't result in the same day; the jump from Thursday (+4) directly to Monday (+5) doesn't make any sense either. Similar considerations apply to negative offsets. I've rewritten the implementation to make more sense (though it no longer exactly matches the bug report), and increased the range for the test. Let me know if any part of it still needs improvement. |
|
Comment on behalf of stas at php.net: merged |
https://bugs.php.net/bug.php?id=61642