Doc #60353 [NEW]: Date-related "Relative Formats" doesn't indicate month behaviour
| From: | frozenfire@php.net | Date: | Mon, 21 Nov 2011 22:05:44 +0000 |
| Subject: | Doc #60353 [NEW]: Date-related "Relative Formats" doesn't indicate month behaviour | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-7458@lists.php.net to get a copy of this message | ||
From:
Operating system:
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Date-related "Relative Formats" doesn't indicate month behaviour
Description:
------------
A fellow on reddit.com/r/PHP mentioned that the documentation for Relative
Formats for dates is missing information on how relative months work.
Here's the relevant comment:
http://www.reddit.com/r/PHP/comments/mk3ub/strtotime_wtf/c31lhav
"echo date("Y-m-d", strtotime("+1 month 2011-11-30"));
returns: 2011-12-30 // wtf? but I wanted 2011-12-31
This is why you don't use months when calculating dates. A month is
ambiguous.
Think about it - since months vary, which month is it supposed to use to
calculate 1 month? November or December?
Since The starting date is in November, it assumes that is the first month
it
should start calculating from. So, for the first iteration, 1 month is 30
days.
However, it recalculates what a month is for every iteration.
consider this:
echo date("Y-m-d", strtotime("+1 month 2011-11-30"));
// 2011-12-30 or 30 days
echo date("Y-m-d", strtotime("+2 month 2011-11-30"));
// 2012-01-30 or 61 days
echo date("Y-m-d", strtotime("+30 days 2011-11-30"));
// 2011-12-30
echo date("Y-m-d", strtotime("+60 days 2011-11-30"));
// 2012-01-29
Notice how when I use +2 months it suddenly becomes 61 days. This is
because it
starts in December on the second iteration, and it recalculates what a
month is
based on that."
This behaviour should be documented in the datetime.formats.relative
document.
--
Edit bug report at https://bugs.php.net/bug.php?id=60353&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60353&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60353&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60353&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=60353&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60353&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=60353&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=60353&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=60353&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=60353&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=60353&r=support
Expected behavior: https://bugs.php.net/fix.php?id=60353&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=60353&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=60353&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=60353&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60353&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=60353&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=60353&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=60353&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=60353&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=60353&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=60353&r=mysqlcfg