note 123627 added to datetime.modify
| From: | vittorio dot zamparella at gmail dot com | Date: | Mon, 18 Feb 2019 16:53:33 +0000 |
| Subject: | note 123627 added to datetime.modify | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210262@lists.php.net to get a copy of this message | ||
@Anonimous
There is no bug. Especially not any retarded one.
<?
function plusOneMonthTests($dateString, $expectation) {
$date = new DateTime($dateString);
echo "[".$date->format('Y-m-d')."] +1 month =
[".$date->modify('+1 month')->format('Y-m-d')."] $expectation
\n";
}
plusOneMonthTests('2001-01-01', 'as expected');
plusOneMonthTests('2001-01-27', 'as expected');
plusOneMonthTests('2001-01-28', 'as expected');
plusOneMonthTests('2001-01-29', 'what would you expect?');
plusOneMonthTests('2001-01-30', 'what would you expect?');
plusOneMonthTests('2001-01-31', 'what would you expect?');
?>
Result:
[2001-01-01] +1 month = [2001-02-01] as expected
[2001-01-27] +1 month = [2001-02-27] as expected
[2001-01-28] +1 month = [2001-02-28] as expected
[2001-01-29] +1 month = [2001-03-01] what would you expect? 29 of february??
[2001-01-30] +1 month = [2001-03-02] what would you expect? or 30 of february?
[2001-01-31] +1 month = [2001-03-03] what would you expect?
As with any tool you need to know how to use it.
I think most people are looking for "the same day of the next month" (or any other number
or months).
The calendar is twisted, don't blame the library.
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.142 (proxied: 109.116.148.28)
----
Manual Page -- http://php.net/manual/en/datetime.modify.php
Edit -- https://master.php.net/note/edit/123627
Del: integrated -- https://master.php.net/note/delete/123627/integrated
Del: useless -- https://master.php.net/note/delete/123627/useless
Del: bad code -- https://master.php.net/note/delete/123627/bad+code
Del: spam -- https://master.php.net/note/delete/123627/spam
Del: non-english -- https://master.php.net/note/delete/123627/non-english
Del: in docs -- https://master.php.net/note/delete/123627/in+docs
Del: other reasons-- https://master.php.net/note/delete/123627
Reject -- https://master.php.net/note/reject/123627
Search -- https://master.php.net/manage/user-notes.php