Bug #62193 [Com]: strtotime returning wrong month

2013-05-31 Thread phpbugs at theHiltons dot net
Edit report at https://bugs.php.net/bug.php?id=62193&edit=1

 ID: 62193
 Comment by: phpbugs at theHiltons dot net
 Reported by:thomasrothwell dot 1990 at gmail dot com
 Summary:strtotime returning wrong month
 Status: Open
 Type:   Bug
 Package:*Data Exchange functions
 Operating System:   Ubuntu 12.04 LTS & Ubuntu 10.04
 PHP Version:5.3Git-2012-05-31 (Git)
 Block user comment: N
 Private report: N

 New Comment:

Reproduced May 31st, 2013, CentOS 64Bit, PHP 5.4.15:
foreach (['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 
'Nov', 'Dec'] as $monthName) {
echo "getdate(strtotime('$monthName'))['month'] = " . 
getdate(strtotime($monthName))['month'] . "\n";
echo "getdate(strtotime('$monthName'))['mon'] = " . 
getdate(strtotime($monthName))['mon'] . "\n";
}


Previous Comments:

[2012-05-31 02:25:24] thomasrothwell dot 1990 at gmail dot com

Assuming the issue is related to June only having 30 days, which then pushes it 
to the next month July.


Expected: 06
Result: 07

I've only noticed this occur Today (31st of May 2012).

Altered my php.ini to use the following config as well:

date.timezone = "Australia/Sydney"
date.default_latitude = -35.308142
date.default_longitude = 149.124518

Thinking it could be a timezone issue. Also attempted use of gmdate.

What I found to work was:

Expected: 06
Result: 06


Test script:
---
https://bugs.php.net/bug.php?id=62193&edit=1


Bug #62193 [Com]: strtotime returning wrong month

2013-05-31 Thread phpbugs at thehiltons dot net
Edit report at https://bugs.php.net/bug.php?id=62193&edit=1

 ID: 62193
 Comment by: phpbugs at thehiltons dot net
 Reported by:thomasrothwell dot 1990 at gmail dot com
 Summary:strtotime returning wrong month
 Status: Not a bug
 Type:   Bug
 Package:Date/time related
 Operating System:   Ubuntu 12.04 LTS & Ubuntu 10.04
 PHP Version:5.3Git-2012-05-31 (Git)
 Block user comment: N
 Private report: N

 New Comment:

How this is an overflow issue:

$timeStr =  strtotime('Jun'); // just 'Jun'
$date = getdate($timeStr);

The date represented by $date should be in June, but it's not.
Since I didn't specify a day it shouldn't be an overflow issue.
If the day is assumed/implied by the current day then that should be documented.
I would argue that since it is not specified, the 1st of the month at 0:00:00 
is 
the safest assumption.


Previous Comments:

[2013-05-31 18:10:57] ahar...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

PHP date functions will overflow out of bound values: since June 31 doesn't 
exist, it becomes July 1.

----------------
[2013-05-31 15:29:50] phpbugs at theHiltons dot net

Reproduced May 31st, 2013, CentOS 64Bit, PHP 5.4.15:
foreach (['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 
'Nov', 'Dec'] as $monthName) {
echo "getdate(strtotime('$monthName'))['month'] = " . 
getdate(strtotime($monthName))['month'] . "\n";
echo "getdate(strtotime('$monthName'))['mon'] = " . 
getdate(strtotime($monthName))['mon'] . "\n";
}


[2012-05-31 02:25:24] thomasrothwell dot 1990 at gmail dot com

Assuming the issue is related to June only having 30 days, which then pushes it 
to the next month July.


Expected: 06
Result: 07

I've only noticed this occur Today (31st of May 2012).

Altered my php.ini to use the following config as well:

date.timezone = "Australia/Sydney"
date.default_latitude = -35.308142
date.default_longitude = 149.124518

Thinking it could be a timezone issue. Also attempted use of gmdate.

What I found to work was:

Expected: 06
Result: 06


Test script:
---
https://bugs.php.net/bug.php?id=62193&edit=1


Bug #62193 [Com]: strtotime returning wrong month

2013-06-05 Thread phpbugs at thehiltons dot net
Edit report at https://bugs.php.net/bug.php?id=62193&edit=1

 ID: 62193
 Comment by: phpbugs at thehiltons dot net
 Reported by:thomasrothwell dot 1990 at gmail dot com
 Summary:strtotime returning wrong month
 Status: Not a bug
 Type:   Bug
 Package:Date/time related
 Operating System:   Ubuntu 12.04 LTS & Ubuntu 10.04
 PHP Version:5.3Git-2012-05-31 (Git)
 Block user comment: N
 Private report: N

 New Comment:

Fair enough. Thank you both for taking the time to respond to this.

I would love to see the docs updated to be more specific about this.


Previous Comments:

[2013-05-31 23:41:31] ras...@php.net

This is standard UNIX behaviour. You need to be explicit as you discovered. Try 
the same thing in a shell script, for example:

$ date
Fri May 31 16:37:45 PDT 2013
$ date --date='+1 month' +'Next month is %B'
Next month is July

SQLite and many other tools you will come across follow this same standard 
behaviour when it comes to data manipulation. It is described by GNU here:

http://www.gnu.org/software/tar/manual/html_node/Relative-items-in-date-
strings.html#SEC120

There is really no good answer to this one. We can't just assume the 1st of the 
month, because then adding 1 day would be equivalent to adding 1 month on the 
last day of the month. That's a huge amount of data loss. So we follow the 
UNIX/GNU convention.

--------
[2013-05-31 19:37:22] phpbugs at thehiltons dot net

How this is an overflow issue:

$timeStr =  strtotime('Jun'); // just 'Jun'
$date = getdate($timeStr);

The date represented by $date should be in June, but it's not.
Since I didn't specify a day it shouldn't be an overflow issue.
If the day is assumed/implied by the current day then that should be documented.
I would argue that since it is not specified, the 1st of the month at 0:00:00 
is 
the safest assumption.


[2013-05-31 18:10:57] ahar...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

PHP date functions will overflow out of bound values: since June 31 doesn't 
exist, it becomes July 1.

--------------------
[2013-05-31 15:29:50] phpbugs at theHiltons dot net

Reproduced May 31st, 2013, CentOS 64Bit, PHP 5.4.15:
foreach (['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 
'Nov', 'Dec'] as $monthName) {
echo "getdate(strtotime('$monthName'))['month'] = " . 
getdate(strtotime($monthName))['month'] . "\n";
echo "getdate(strtotime('$monthName'))['mon'] = " . 
getdate(strtotime($monthName))['mon'] . "\n";
}


[2012-05-31 02:25:24] thomasrothwell dot 1990 at gmail dot com

Assuming the issue is related to June only having 30 days, which then pushes it 
to the next month July.

https://bugs.php.net/bug.php?id=62193


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62193&edit=1