-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: add Time::addCalendarMonths() function #9528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.7
Are you sure you want to change the base?
feat: add Time::addCalendarMonths() function #9528
Conversation
Sounds useful. In addition to fixing PHPStan, we also need:
|
Happy to write tests/docs/changelog. I had tried returntype Time brefore but this also returns an error. Functions like addMonth() do not have any return type specified. What is the correct type? Is there a way to run PHPStan only on one file, or does this break the testing? |
For phpstan, you should run it on the whole codebase, not just the changed file. For testing, you can just add your example as a data provider then test on them.
|
Thank you, I figured out I need to run on the whole code base. Error should be gone now. I wrote tests similar to |
Co-authored-by: John Paul E. Balandan, CPA <[email protected]>
revert change to TimeTrait::setTimeNow()
…deIgniter4 into 4.7-addCalendarMonth
2deaf0c
to
6492d71
Compare
Co-authored-by: Michal Sniatala <[email protected]>
The
Time::addMonths()
could return an undesired behaviour if a date in the next calandar month is desired. For example,Time(2025-01-31)->addMonths(1)
results in2025-03-03
while a date in february may be desired, orTime(2025-03-31)->addMonths(1)
results in a date in May not in April.The
addCalendarMonths
function returns a new date in the next calendar month.New: Also implemented
subCalendarMonths
function to return a new date in a previous calendar month.Of course, this only applies if the dev is looking for a date in the next calendar month (months are weird of course, it is 30, 31, 28, 29 days...? who knows).
If deemed worthy to include in 4.7 I will write test and documentation.
Comparison between
addMonths()
andaddCalendarMonths()
Checklist: