Send a blank email to [email protected] to get a copy of this message
Author: David Carlier (devnexen)
Date: 2025-05-03T16:56:09+01:00
Commit: https://github.com/php/php-src/commit/0227d96f48ffadac0e4eae81eb91bfabf0ba754f
Raw diff: https://github.com/php/php-src/commit/0227d96f48ffadac0e4eae81eb91bfabf0ba754f.diff
Fix GH-18481: date_sunrise check sun rise with offset if is finite/is nan
close GH-18484
Changed paths:
A ext/date/tests/gh18481.phpt
M NEWS
M ext/date/php_date.c
Diff:
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--
+<?php
+
+foreach ([-NAN, NAN, INF, -INF] as $offset) {
+ var_dump(date_sunrise(time(), SUNFUNCS_RET_STRING, 38.4, -9, 90, $offset));
+}
+?>
+--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)