php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68367 Before 1915 datetime->diff works wrong
Submitted: 2014-11-06 17:51 UTC Modified: 2014-11-07 15:05 UTC
From: xguiga at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.5.18 OS: OSX Maveriks and Ubuntu 14.10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: xguiga at gmail dot com
New email:
PHP Version: OS:

 

 [2014-11-06 17:51 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-07 13:12 UTC] aharvey@php.net
-Status: Open +Status: Feedback
 [2014-11-07 13:12 UTC] aharvey@php.net
What time zone is PHP using? You can check that with date_default_timezone_get().
 [2014-11-07 13:40 UTC] xguiga at gmail dot com
-Status: Feedback +Status: Open
 [2014-11-07 13:40 UTC] xguiga at gmail dot com
The timezone is: America/Sao_Paulo
 [2014-11-07 13:51 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2014-11-07 13:51 UTC] 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 15:05 UTC] xguiga at gmail dot com
Sorry, it's ok! you are right!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 27 16:01:27 2024 UTC