Bug Report #4692

Date::span - not working properly

Added by Valeriy Volkov about 1 year ago. Updated about 1 year ago.

Status:NewStart date:01/28/2013
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-
Resolution: Points:1

Description

This code :
foreach(array(1960, 1970, 1980, 1990) as $year) {
var_dump(date('Y-m-d'), date($year.'-m-d'), Date::span(strtotime(date('Y-m-d')), strtotime(date($year.'-m-d'))));
}

Produce following output:
string '2013-01-28' (length=10)
string '1960-01-28' (length=10)
array (size=7)
'years' => int 53
'months' => int 0
'weeks' => int 0
'days' => int 1
'hours' => int 3
'minutes' => int 55
'seconds' => int 22

string '2013-01-28' (length=10)
string '1970-01-28' (length=10)
array (size=7)
'years' => int 43
'months' => int 0
'weeks' => int 0
'days' => int 0
'hours' => int 14
'minutes' => int 3
'seconds' => int 2

string '2013-01-28' (length=10)
string '1980-01-28' (length=10)
array (size=7)
'years' => int 33
'months' => int 0
'weeks' => int 0
'days' => int 1
'hours' => int 0
'minutes' => int 10
'seconds' => int 42

string '2013-01-28' (length=10)
string '1990-01-28' (length=10)
array (size=7)
'years' => int 23
'months' => int 0
'weeks' => int 0
'days' => int 0
'hours' => int 10
'minutes' => int 18
'seconds' => int 22

Instead of showing just (53, 43, 33, 23) years with other values set to 0 it produce unexpected results.
When taking span from : '2013-01-28' and '1980-01-28' it showing 1 day difference!

History

#1 Updated by Valeriy Volkov about 1 year ago

Example with DateTime class introduced in php 5.3.0 wich is worked as expected :

foreach(array(1960, 1970, 1980, 1990) as $year) {
echo '

';
    $datetime1 = new DateTime(date('Y-m-d'));
    $datetime2 = new DateTime(date($year.'-m-d'));
    $interval = $datetime1->diff($datetime2);
    var_dump($interval);
}

Also available in: Atom PDF