From 0227d96f48ffadac0e4eae81eb91bfabf0ba754f Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 2 May 2025 07:24:15 +0100 Subject: [PATCH] Fix GH-18481: date_sunrise check sun rise with offset if is finite/is nan close GH-18484 --- NEWS | 2 ++ ext/date/php_date.c | 2 +- ext/date/tests/gh18481.phpt | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ext/date/tests/gh18481.phpt diff --git a/NEWS b/NEWS index a0df1b1b6ce..c2e0418487b 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 d8a0704ca25..2347fd55706 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 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)