Browse Source
- Fixed bug #49081 (DateTime::diff() mistake if start in January and interval >
- Fixed bug #49081 (DateTime::diff() mistake if start in January and interval >
28 days). (Derick)experimental/lemon
4 changed files with 130 additions and 26 deletions
-
2ext/date/lib/interval.c
-
75ext/date/lib/tm2unixtime.c
-
22ext/date/tests/bug49081.phpt
-
57ext/date/tests/date_diff.phpt
@ -0,0 +1,22 @@ |
|||
--TEST-- |
|||
Bug #49081 (DateTime::diff() mistake if start in January and interval > 28 days) |
|||
--FILE-- |
|||
<?php |
|||
date_default_timezone_set('Europe/Berlin'); |
|||
$d1 = new DateTime('2010-01-01 06:00:00'); |
|||
$d2 = new DateTime('2010-01-31 10:00:00'); |
|||
$d = $d1->diff($d2); |
|||
print_r($d); |
|||
?> |
|||
--EXPECT-- |
|||
DateInterval Object |
|||
( |
|||
[y] => 0 |
|||
[m] => 0 |
|||
[d] => 30 |
|||
[h] => 4 |
|||
[i] => 0 |
|||
[s] => 0 |
|||
[invert] => 0 |
|||
[days] => 30 |
|||
) |
|||
@ -0,0 +1,57 @@ |
|||
--TEST-- |
|||
Extensive test for date_diff(). |
|||
--FILE-- |
|||
<?php |
|||
$ok = 0; |
|||
define( 'COUNT', 120 ); |
|||
$d0 = new DateTime('2009-11-20'); |
|||
for ( $i = 0; $i < COUNT * 12; $i++ ) |
|||
{ |
|||
$d = clone $d0; |
|||
$dates[$i] = $d->add( new DateInterval( "P{$i}D" ) ); |
|||
} |
|||
|
|||
for ( $i = 0; $i < COUNT; $i++) |
|||
{ |
|||
// echo $dates[$i]->format( "Y-m-d\n" ); |
|||
for ( $j = 0; $j < COUNT * 12; $j++) |
|||
{ |
|||
$diff = date_diff( $dates[$i], $dates[$j] ); |
|||
/* |
|||
printf( "\t%s %s %3d %s\n", |
|||
$dates[$i]->format( 'Y-m-d' ), |
|||
$dates[$j]->format( 'Y-m-d' ), |
|||
$diff->format( '%a' ), |
|||
$diff->format( '%y-%m-%d' ) |
|||
); |
|||
*/ |
|||
|
|||
$current = clone $dates[$i]; |
|||
$int = new DateInterval( $diff->format( 'P%yY%mM%dD' ) ); |
|||
if ( $current > $dates[$j] ) |
|||
{ |
|||
$current->sub( $int ); |
|||
} |
|||
else |
|||
{ |
|||
$current->add( $int ); |
|||
} |
|||
if ( $current != $dates[$j] ) |
|||
{ |
|||
echo "FAIL: ", |
|||
$dates[$i]->format( 'Y-m-d' ), " + ", |
|||
$int->format( '%y-%m-%d' ), " = ", |
|||
$current->format( 'Y-m-d' ), " (", |
|||
$dates[$j]->format( 'Y-m-d' ), ")\n"; |
|||
} |
|||
else |
|||
{ |
|||
$ok++; |
|||
} |
|||
} |
|||
} |
|||
|
|||
echo $ok, "\n"; |
|||
?> |
|||
--EXPECT-- |
|||
172800 |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue