Bug #68367 [Nab]: Before 1915 datetime->diff works wrong

From: Date: Fri, 07 Nov 2014 15:05:39 +0000
Subject: Bug #68367 [Nab]: Before 1915 datetime->diff works wrong
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188511@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68367&edit=1 ID: 68367 User updated by: xguiga at gmail dot com Reported by: xguiga at gmail dot com Summary: Before 1915 datetime->diff works wrong Status: Not a bug Type: Bug Package: Date/time related Operating System: OSX Maveriks and Ubuntu 14.10 PHP Version: 5.5.18 Block user comment: N Private report: N New Comment: Sorry, it's ok! you are right! Previous Comments: ------------------------------------------------------------------------ [2014-11-07 13:51:50] aharvey@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 Before 1914, Sao Paulo was at UTC-3:06:28, instead of its present UTC-3. You can see this via zdump: aharvey@aharvey-mba:~$ zdump -v /usr/share/zoneinfo/America/Sao_Paulo | head -4 /usr/share/zoneinfo/America/Sao_Paulo Fri Dec 13 20:45:52 1901 UTC = Fri Dec 13 17:39:24 1901 LMT isdst=0 /usr/share/zoneinfo/America/Sao_Paulo Sat Dec 14 20:45:52 1901 UTC = Sat Dec 14 17:39:24 1901 LMT isdst=0 /usr/share/zoneinfo/America/Sao_Paulo Thu Jan 1 03:06:27 1914 UTC = Wed Dec 31 23:59:59 1913 LMT isdst=0 /usr/share/zoneinfo/America/Sao_Paulo Thu Jan 1 03:06:28 1914 UTC = Thu Jan 1 00:06:28 1914 BRT isdst=0 DateInterval takes this into account when calculating the difference. ------------------------------------------------------------------------ [2014-11-07 13:40:24] xguiga at gmail dot com The timezone is: America/Sao_Paulo ------------------------------------------------------------------------ [2014-11-07 13:12:27] aharvey@php.net What time zone is PHP using? You can check that with date_default_timezone_get(). ------------------------------------------------------------------------ [2014-11-06 17:51:08] xguiga at gmail dot com Description: ------------ I tried make an diff in 1899-01-01 and 1970-01-01 and don't return only year difference, return months, days, hours, minutes and seconds. I made some tests, and date before 1915 this happend. Test script: --------------- var_dump((new \DateTime('1912-01-01'))->diff(new \DateTime('1915-01-01'))); Expected result: ---------------- object(DateInterval)[2405] public 'y' => int 3 public 'm' => int 0 public 'd' => int 0 public 'h' => int 0 public 'i' => int 0 public 's' => int 0 public 'weekday' => int 0 public 'weekday_behavior' => int 0 public 'first_last_day_of' => int 0 public 'invert' => int 0 public 'days' => int 1095 public 'special_type' => int 0 public 'special_amount' => int 0 public 'have_weekday_relative' => int 0 public 'have_special_relative' => int 0 Actual result: -------------- object(DateInterval)[2405] public 'y' => int 2 public 'm' => int 11 public 'd' => int 30 public 'h' => int 23 public 'i' => int 53 public 's' => int 32 public 'weekday' => int 0 public 'weekday_behavior' => int 0 public 'first_last_day_of' => int 0 public 'invert' => int 0 public 'days' => int 1095 public 'special_type' => int 0 public 'special_amount' => int 0 public 'have_weekday_relative' => int 0 public 'have_special_relative' => int 0 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68367&edit=1

« previous php.bugs (#188511) next »