diff --git a/NEWS b/NEWS index a0df1b1b6ce1c..c2e0418487bfd 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 d8a0704ca250a..2347fd55706fa 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -5346,7 +5346,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 0000000000000..6617a19474461 --- /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)