Bug #68503 [NEW]: date_diff on two dates with timezone set localised returns wrong results
| From: | chris at vostron dot com | Date: | Wed, 26 Nov 2014 10:36:11 +0000 |
| Subject: | Bug #68503 [NEW]: date_diff on two dates with timezone set localised returns wrong results | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-188797@lists.php.net to get a copy of this message | ||
From: chris at vostron dot com
Operating system: Ubuntu Trusty
PHP version: 5.6.3
Package: Date/time related
Bug Type: Bug
Bug description:date_diff on two dates with timezone set localised returns wrong results
Description:
------------
When using date_diff in a localised time zone and the date_diff will
traverse a daylight saving boundary, the number of days returned is 1
fewer than expected.
This is understandable given the missing hour. However, it doesn't then
set the "h" value to 23, which would be expected. Other option is that
if we're not going to compare hours/mins/seconds when only passed a
date, it should return "m" of 3, "d" of 0 in the example script.
Test script:
---------------
date_default_timezone_set('Europe/London');
var_dump(date_diff(new DateTime("2015-02-01"), new
DateTime("2015-05-01")));
date_default_timezone_set('UTC');
var_dump(date_diff(new DateTime("2015-02-01"), new
DateTime("2015-05-01")));
Expected result:
----------------
object(DateInterval)#3 (15) {
["y"]=>
int(0)
["m"]=>
int(3)
["d"]=>
int(0)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(89)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
object(DateInterval)#2 (15) {
["y"]=>
int(0)
["m"]=>
int(3)
["d"]=>
int(0)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(89)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
-- OR --
object(DateInterval)#3 (15) {
["y"]=>
int(0)
["m"]=>
int(2)
["d"]=>
int(30)
["h"]=>
int(23)
["i"]=>
int(0)
["s"]=>
int(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(89)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
object(DateInterval)#2 (15) {
["y"]=>
int(0)
["m"]=>
int(3)
["d"]=>
int(0)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(89)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
Actual result:
--------------
object(DateInterval)#3 (15) {
["y"]=>
int(0)
["m"]=>
int(2)
["d"]=>
int(30)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(89)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
object(DateInterval)#2 (15) {
["y"]=>
int(0)
["m"]=>
int(3)
["d"]=>
int(0)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(89)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
--
Edit bug report at https://bugs.php.net/bug.php?id=68503&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68503&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68503&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68503&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68503&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68503&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68503&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68503&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68503&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68503&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68503&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68503&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68503&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68503&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68503&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68503&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68503&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68503&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68503&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68503&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68503&r=mysqlcfg