diff --git a/NEWS b/NEWS index 295ae06a498..fe7b2e88a3c 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,8 @@ PHP NEWS . Fixed bug GH-18076 (Since PHP 8, the date_sun_info() function returns inaccurate sunrise and sunset times, but other calculated times are correct) (JiriJozif). + . Fixed bug GH-18481 (date_sunrise with unexpected nan value for the offset). + (nielsdos/David Carlier) - Intl: . Fix various reference issues. (nielsdos) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index fd49ac9a63c..834db1e226c 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -5573,7 +5573,7 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, bool calc_s if (N > 24 || N < 0) { N -= floor(N / 24) * 24; } - if (N > 24 || N < 0) { + if (!(N <= 24 && N >= 0)) { RETURN_FALSE; } diff --git a/ext/date/tests/gh18481.phpt b/ext/date/tests/gh18481.phpt new file mode 100644 index 00000000000..6617a194744 --- /dev/null +++ b/ext/date/tests/gh18481.phpt @@ -0,0 +1,21 @@ +--TEST-- +GH-18481 (date_sunrise with utcOffset as INF) +--FILE-- + +--EXPECTF-- +Deprecated: Function date_sunrise() is deprecated in %s on line %d +bool(false) + +Deprecated: Function date_sunrise() is deprecated in %s on line %d +bool(false) + +Deprecated: Function date_sunrise() is deprecated in %s on line %d +bool(false) + +Deprecated: Function date_sunrise() is deprecated in %s on line %d +bool(false)