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

 ID:                 64448
 Updated by:         ras...@php.net
 Reported by:        xojins at gmail dot com
 Summary:            DATE Day of Week bug for 3-10-2013
 Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 Operating System:   RedHat EL5
 PHP Version:        5.3.23
 Block user comment: N
 Private report:     N

 New Comment:

You have discovered DST. You can't assume all days will have 86400 seconds. PHP 
is correct here.


Previous Comments:
------------------------------------------------------------------------
[2013-03-18 21:03:46] ahar...@php.net

This is due to daylight saving starting on March 10 in both of those time 
zones: March 10 only had 23 hours, so subtracting 24 hours from 12:00 am on 
March 11 results in $d2 being 11 pm on March 9.

------------------------------------------------------------------------
[2013-03-18 20:59:59] xojins at gmail dot com

I have tested this with the following timezones:
America/New_York
US/Pacific

Also tested with PHP 5.4.12 and 5.5.0 alpha 5. All exhibit the same symptom.

------------------------------------------------------------------------
[2013-03-18 20:56:10] ahar...@php.net

Which time zone is PHP configured to operate in (ie what do you get if you echo 
date_default_timezone_get())?

------------------------------------------------------------------------
[2013-03-18 20:47:40] xojins at gmail dot com

Description:
------------
When using the DATE function and returning the day of the week (lowercase L 
format) returns the wrong day of the week for 3/10/2013.

The example provided shows subtracting 86400 seconds from 
strtotime('03/11/2013') 
to return 1362888000 seconds. When passed to DATE, it returns Saturday. This is 
wrong and should be Sunday.

You need to add 3600 to any value to calculate 3/10/13 correctly.


Test script:
---------------
$d1 = date('l', strtotime('03/12/2013')-(60*60*24));  //date('l', 1363060800 - 
86400) = date('l', 1362974400) = Monday

$d2 =date('l', strtotime('03/11/2013')-(60*60*24));  //date('l', 1362974400 - 
86400) = date('l', 1362888000) = Saturday != date('m-d-y', 1362888000)

$d3 =date('l', strtotime('03/10/2013')-(60*60*24));  //date('l', 1362891600 - 
86400) = date('l', 1362805200) = Saturday 

echo $d1 . '<br>';
echo $d2 . '<br>';
echo $d3 . '<br>';

Expected result:
----------------
Monday
Sunday
Saturday

Actual result:
--------------
Monday
Saturday
Saturday


------------------------------------------------------------------------



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

Reply via email to