summaryrefslogtreecommitdiff
path: root/ext/date
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2021-03-04 12:27:31 +0300
committerDmitry Stogov <dmitry@zend.com>2021-03-04 12:27:31 +0300
commitb4e9b1846376f562e27a13572a137ec584c13f58 (patch)
tree6cbea3947797e42315f11756823f89ea171e8a19 /ext/date
parent500b4b4945e3768afd2cfcae61548ef47e7f003f (diff)
downloadphp-git-b4e9b1846376f562e27a13572a137ec584c13f58.tar.gz
Avoid useless date conversion
Diffstat (limited to 'ext/date')
-rw-r--r--ext/date/php_date.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 4e840a3106..a12f00957b 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -2270,6 +2270,14 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size
timelib_unixtime2local(now, (timelib_sll) sec);
php_date_set_time_fraction(now, usec);
+ if (!format
+ && time_str_len == sizeof("now") - 1
+ && memcmp(time_str, "now", sizeof("now") - 1) == 0) {
+ timelib_time_dtor(dateobj->time);
+ dateobj->time = now;
+ return 1;
+ }
+
options = TIMELIB_NO_CLONE;
if (flags & PHP_DATE_INIT_FORMAT) {
options |= TIMELIB_OVERRIDE_TIME;
@@ -3320,7 +3328,10 @@ PHP_FUNCTION(date_timestamp_get)
}
dateobj = Z_PHPDATE_P(object);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
- timelib_update_ts(dateobj->time, NULL);
+
+ if (!dateobj->time->sse_uptodate) {
+ timelib_update_ts(dateobj->time, NULL);
+ }
timestamp = timelib_date_to_int(dateobj->time, &epoch_does_not_fit_in_zend_long);