mirror of
https://github.com/php/php-src.git
synced 2024-11-27 20:03:40 +08:00
Merge branch 'PHP-8.1' into PHP-8.2
This commit is contained in:
commit
1b5360587e
@ -379,7 +379,7 @@ typedef struct _timelib_tzdb {
|
||||
#define TIMELIB_OVERRIDE_TIME 0x01
|
||||
#define TIMELIB_NO_CLONE 0x02
|
||||
|
||||
#define TIMELIB_UNSET -99999
|
||||
#define TIMELIB_UNSET -9999999
|
||||
|
||||
/* An entry for each of these error codes is also in the
|
||||
* timelib_error_messages array in timelib.c.
|
||||
|
@ -2176,7 +2176,7 @@ static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTabl
|
||||
ZVAL_DOUBLE(&zv, (double)intervalobj->diff->us / 1000000.0);
|
||||
zend_hash_str_update(props, "f", sizeof("f") - 1, &zv);
|
||||
PHP_DATE_INTERVAL_ADD_PROPERTY("invert", invert);
|
||||
if (intervalobj->diff->days != -99999) {
|
||||
if (intervalobj->diff->days != TIMELIB_UNSET) {
|
||||
PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
|
||||
} else {
|
||||
ZVAL_FALSE(&zv);
|
||||
@ -2969,7 +2969,7 @@ void php_date_do_return_parsed_time(INTERNAL_FUNCTION_PARAMETERS, timelib_time *
|
||||
|
||||
array_init(return_value);
|
||||
#define PHP_DATE_PARSE_DATE_SET_TIME_ELEMENT(name, elem) \
|
||||
if (parsed_time->elem == -99999) { \
|
||||
if (parsed_time->elem == TIMELIB_UNSET) { \
|
||||
add_assoc_bool(return_value, #name, 0); \
|
||||
} else { \
|
||||
add_assoc_long(return_value, #name, parsed_time->elem); \
|
||||
@ -2981,7 +2981,7 @@ void php_date_do_return_parsed_time(INTERNAL_FUNCTION_PARAMETERS, timelib_time *
|
||||
PHP_DATE_PARSE_DATE_SET_TIME_ELEMENT(minute, i);
|
||||
PHP_DATE_PARSE_DATE_SET_TIME_ELEMENT(second, s);
|
||||
|
||||
if (parsed_time->us == -99999) {
|
||||
if (parsed_time->us == TIMELIB_UNSET) {
|
||||
add_assoc_bool(return_value, "fraction", 0);
|
||||
} else {
|
||||
add_assoc_double(return_value, "fraction", (double)parsed_time->us / 1000000.0);
|
||||
@ -3117,21 +3117,21 @@ static bool php_date_modify(zval *object, char *modify, size_t modify_len) /* {{
|
||||
dateobj->time->have_relative = tmp_time->have_relative;
|
||||
dateobj->time->sse_uptodate = 0;
|
||||
|
||||
if (tmp_time->y != -99999) {
|
||||
if (tmp_time->y != TIMELIB_UNSET) {
|
||||
dateobj->time->y = tmp_time->y;
|
||||
}
|
||||
if (tmp_time->m != -99999) {
|
||||
if (tmp_time->m != TIMELIB_UNSET) {
|
||||
dateobj->time->m = tmp_time->m;
|
||||
}
|
||||
if (tmp_time->d != -99999) {
|
||||
if (tmp_time->d != TIMELIB_UNSET) {
|
||||
dateobj->time->d = tmp_time->d;
|
||||
}
|
||||
|
||||
if (tmp_time->h != -99999) {
|
||||
if (tmp_time->h != TIMELIB_UNSET) {
|
||||
dateobj->time->h = tmp_time->h;
|
||||
if (tmp_time->i != -99999) {
|
||||
if (tmp_time->i != TIMELIB_UNSET) {
|
||||
dateobj->time->i = tmp_time->i;
|
||||
if (tmp_time->s != -99999) {
|
||||
if (tmp_time->s != TIMELIB_UNSET) {
|
||||
dateobj->time->s = tmp_time->s;
|
||||
} else {
|
||||
dateobj->time->s = 0;
|
||||
@ -3142,7 +3142,7 @@ static bool php_date_modify(zval *object, char *modify, size_t modify_len) /* {{
|
||||
}
|
||||
}
|
||||
|
||||
if (tmp_time->us != -99999) {
|
||||
if (tmp_time->us != TIMELIB_UNSET) {
|
||||
dateobj->time->us = tmp_time->us;
|
||||
}
|
||||
|
||||
@ -4226,7 +4226,7 @@ static zval *date_interval_read_property(zend_object *object, zend_string *name,
|
||||
|
||||
if (fvalue != -1) {
|
||||
ZVAL_DOUBLE(retval, fvalue);
|
||||
} else if (value != -99999) {
|
||||
} else if (value != TIMELIB_UNSET) {
|
||||
ZVAL_LONG(retval, value);
|
||||
} else {
|
||||
ZVAL_FALSE(retval);
|
||||
@ -4385,7 +4385,7 @@ static void php_date_interval_initialize_from_hash(zval **return_value, php_inte
|
||||
do { \
|
||||
zval *z_arg = zend_hash_str_find(myht, "days", sizeof("days") - 1); \
|
||||
if (z_arg && Z_TYPE_P(z_arg) == IS_FALSE) { \
|
||||
(*intobj)->diff->member = -99999; \
|
||||
(*intobj)->diff->member = TIMELIB_UNSET; \
|
||||
} else if (z_arg && Z_TYPE_P(z_arg) <= IS_STRING) { \
|
||||
zend_string *str = zval_get_string(z_arg); \
|
||||
DATE_A64I((*intobj)->diff->member, ZSTR_VAL(str)); \
|
||||
@ -4626,7 +4626,7 @@ static zend_string *date_interval_format(char *format, size_t format_len, timeli
|
||||
case 'f': length = slprintf(buffer, sizeof(buffer), ZEND_LONG_FMT, (zend_long) t->us); break;
|
||||
|
||||
case 'a': {
|
||||
if ((int) t->days != -99999) {
|
||||
if ((int) t->days != TIMELIB_UNSET) {
|
||||
length = slprintf(buffer, sizeof(buffer), "%d", (int) t->days);
|
||||
} else {
|
||||
length = slprintf(buffer, sizeof(buffer), "(unknown)");
|
||||
|
33
ext/date/tests/bug-gh11368.phpt
Normal file
33
ext/date/tests/bug-gh11368.phpt
Normal file
@ -0,0 +1,33 @@
|
||||
--TEST--
|
||||
Bug GH-11368: Date modify returns invalid datetime
|
||||
--INI--
|
||||
date.timezone=UTC
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$datetime = date_create('2023-06-04');
|
||||
|
||||
$datetime->setTime(1,1,1,1 /* If set to any other number, it works fine */);
|
||||
var_dump($datetime);
|
||||
|
||||
$datetime->modify('-100 ms');
|
||||
var_dump($datetime);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
object(DateTime)#1 (3) {
|
||||
["date"]=>
|
||||
string(26) "2023-06-04 01:01:01.000001"
|
||||
["timezone_type"]=>
|
||||
int(3)
|
||||
["timezone"]=>
|
||||
string(3) "UTC"
|
||||
}
|
||||
object(DateTime)#1 (3) {
|
||||
["date"]=>
|
||||
string(26) "2023-06-04 01:01:00.900001"
|
||||
["timezone_type"]=>
|
||||
int(3)
|
||||
["timezone"]=>
|
||||
string(3) "UTC"
|
||||
}
|
Loading…
Reference in New Issue
Block a user