Skip to content

Commit b4e9b18

Browse files
committed
Avoid useless date conversion
1 parent 500b4b4 commit b4e9b18

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ext/date/php_date.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,14 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size
22702270
timelib_unixtime2local(now, (timelib_sll) sec);
22712271
php_date_set_time_fraction(now, usec);
22722272

2273+
if (!format
2274+
&& time_str_len == sizeof("now") - 1
2275+
&& memcmp(time_str, "now", sizeof("now") - 1) == 0) {
2276+
timelib_time_dtor(dateobj->time);
2277+
dateobj->time = now;
2278+
return 1;
2279+
}
2280+
22732281
options = TIMELIB_NO_CLONE;
22742282
if (flags & PHP_DATE_INIT_FORMAT) {
22752283
options |= TIMELIB_OVERRIDE_TIME;
@@ -3320,7 +3328,10 @@ PHP_FUNCTION(date_timestamp_get)
33203328
}
33213329
dateobj = Z_PHPDATE_P(object);
33223330
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
3323-
timelib_update_ts(dateobj->time, NULL);
3331+
3332+
if (!dateobj->time->sse_uptodate) {
3333+
timelib_update_ts(dateobj->time, NULL);
3334+
}
33243335

33253336
timestamp = timelib_date_to_int(dateobj->time, &epoch_does_not_fit_in_zend_long);
33263337

0 commit comments

Comments
 (0)