feat: add Time::addCalendarMonths() and Time::subCalendarMonths() methods#9528
feat: add Time::addCalendarMonths() and Time::subCalendarMonths() methods#9528paulbalandan merged 12 commits intocodeigniter4:4.7from christianberkman:4.7-addCalendarMonth
Time::addCalendarMonths() and Time::subCalendarMonths() methods#9528Conversation
|
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 <paulbalandan@gmail.com>
revert change to TimeTrait::setTimeNow()
…deIgniter4 into 4.7-addCalendarMonth
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
|
Thank you, @christianberkman 🎉 |
Time::addCalendarMonths() and Time::subCalendarMonths() methods
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-03while a date in february may be desired, orTime(2025-03-31)->addMonths(1)results in a date in May not in April.The
addCalendarMonthsfunction returns a new date in the next calendar month.New: Also implemented
subCalendarMonthsfunction 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: