mirror of
https://github.com/php/php-src.git
synced 2025-01-13 22:44:36 +08:00
Fix bug #54340 (DateTime::add() method bug).
This commit is contained in:
parent
0de2e61cab
commit
991ba13174
@ -2855,14 +2855,13 @@ PHP_FUNCTION(date_add)
|
||||
if (intobj->diff->invert) {
|
||||
bias = -1;
|
||||
}
|
||||
memset(&dateobj->time->relative, 0, sizeof(struct timelib_rel_time));
|
||||
dateobj->time->relative.y = intobj->diff->y * bias;
|
||||
dateobj->time->relative.m = intobj->diff->m * bias;
|
||||
dateobj->time->relative.d = intobj->diff->d * bias;
|
||||
dateobj->time->relative.h = intobj->diff->h * bias;
|
||||
dateobj->time->relative.i = intobj->diff->i * bias;
|
||||
dateobj->time->relative.s = intobj->diff->s * bias;
|
||||
dateobj->time->relative.weekday = 0;
|
||||
dateobj->time->relative.have_weekday_relative = 0;
|
||||
}
|
||||
dateobj->time->have_relative = 1;
|
||||
dateobj->time->sse_uptodate = 0;
|
||||
@ -2902,6 +2901,7 @@ PHP_FUNCTION(date_sub)
|
||||
bias = -1;
|
||||
}
|
||||
|
||||
memset(&dateobj->time->relative, 0, sizeof(struct timelib_rel_time));
|
||||
dateobj->time->relative.y = 0 - (intobj->diff->y * bias);
|
||||
dateobj->time->relative.m = 0 - (intobj->diff->m * bias);
|
||||
dateobj->time->relative.d = 0 - (intobj->diff->d * bias);
|
||||
@ -2909,8 +2909,6 @@ PHP_FUNCTION(date_sub)
|
||||
dateobj->time->relative.i = 0 - (intobj->diff->i * bias);
|
||||
dateobj->time->relative.s = 0 - (intobj->diff->s * bias);
|
||||
dateobj->time->have_relative = 1;
|
||||
dateobj->time->relative.weekday = 0;
|
||||
dateobj->time->relative.have_weekday_relative = 0;
|
||||
dateobj->time->sse_uptodate = 0;
|
||||
|
||||
timelib_update_ts(dateobj->time, NULL);
|
||||
|
43
ext/date/tests/bug54340.phpt
Normal file
43
ext/date/tests/bug54340.phpt
Normal file
@ -0,0 +1,43 @@
|
||||
--TEST--
|
||||
Bug #54340 (DateTime::add() method bug)
|
||||
--INI--
|
||||
date.timezone=UTC
|
||||
--FILE--
|
||||
<?php
|
||||
$interval = new DateInterval('P1D');
|
||||
|
||||
$dt = new DateTime('first day of January 2011');
|
||||
var_dump($dt);
|
||||
|
||||
$dt->add($interval);
|
||||
var_dump($dt);
|
||||
|
||||
$dt = new DateTime('first day of January 2011');
|
||||
|
||||
$dt->sub($interval);
|
||||
var_dump($dt);
|
||||
--EXPECT--
|
||||
object(DateTime)#2 (3) {
|
||||
["date"]=>
|
||||
string(19) "2011-01-01 00:00:00"
|
||||
["timezone_type"]=>
|
||||
int(3)
|
||||
["timezone"]=>
|
||||
string(3) "UTC"
|
||||
}
|
||||
object(DateTime)#2 (3) {
|
||||
["date"]=>
|
||||
string(19) "2011-01-02 00:00:00"
|
||||
["timezone_type"]=>
|
||||
int(3)
|
||||
["timezone"]=>
|
||||
string(3) "UTC"
|
||||
}
|
||||
object(DateTime)#3 (3) {
|
||||
["date"]=>
|
||||
string(19) "2010-12-31 00:00:00"
|
||||
["timezone_type"]=>
|
||||
int(3)
|
||||
["timezone"]=>
|
||||
string(3) "UTC"
|
||||
}
|
Loading…
Reference in New Issue
Block a user