diff --git a/NEWS b/NEWS index eaeb9894e2b2..aa87f6627230 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,9 @@ PHP NEWS passing an array of CURLFile or CURLStringFile objects to CURLOPT_POSTFIELDS. (Sjoerd Langkemper) +- Date: + . Improved performance of strtotime() with "now". (Alexander Danilov) + - FPM: . Use recommended TYPE, HELP order for OpenMetrics metadata. (Marcel Hernandez) diff --git a/UPGRADING b/UPGRADING index 9dbcd594a29a..8558eaadf37d 100644 --- a/UPGRADING +++ b/UPGRADING @@ -215,6 +215,9 @@ PHP 8.7 UPGRADE NOTES . Improved performance of integer to string conversion (string casts, echo, implode(), json_encode(), serialize(), var_export() and others). +- Date: + . Improved performance of strtotime() with "now". + - DOM: . Parsing HTML with Dom\HTMLDocument or innerHTML uses much less memory for small inputs. diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 98c0240400c1..6b3860461ca6 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1119,6 +1119,10 @@ PHP_FUNCTION(strtotime) return; } + if (zend_string_equals_literal(times, "now")) { + RETURN_LONG(!preset_ts_is_null ? preset_ts : php_time()); + } + now = timelib_time_ctor(); now->tz_info = tzi; now->zone_type = TIMELIB_ZONETYPE_ID; diff --git a/ext/date/tests/strtotime.phpt b/ext/date/tests/strtotime.phpt index f55765fa801e..287fd831b20b 100644 --- a/ext/date/tests/strtotime.phpt +++ b/ext/date/tests/strtotime.phpt @@ -8,6 +8,7 @@ $d[] = strtotime("2005-07-14 22:30:41"); $d[] = strtotime("2005-07-14 22:30:41 GMT"); $d[] = strtotime("@1121373041"); $d[] = strtotime("@1121373041 CEST"); +$d[] = strtotime("now", 1121373041); foreach($d as $date) { echo date(DATE_ISO8601, $date), "\n"; @@ -18,3 +19,4 @@ foreach($d as $date) { 2005-07-15T00:30:41+0200 2005-07-14T22:30:41+0200 2005-07-14T22:30:41+0200 +2005-07-14T22:30:41+0200