Skip to content

Commit 0227d96

Browse files
committed
Fix GH-18481: date_sunrise check sun rise with offset if is finite/is nan
close GH-18484
1 parent 24ab0f1 commit 0227d96

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ PHP NEWS
1111
. Fixed bug GH-18076 (Since PHP 8, the date_sun_info() function returns
1212
inaccurate sunrise and sunset times, but other calculated times are
1313
correct) (JiriJozif).
14+
. Fixed bug GH-18481 (date_sunrise with unexpected nan value for the offset).
15+
(nielsdos/David Carlier)
1416

1517
- Intl:
1618
. Fix various reference issues. (nielsdos)

ext/date/php_date.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5346,7 +5346,7 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, bool calc_s
53465346
if (N > 24 || N < 0) {
53475347
N -= floor(N / 24) * 24;
53485348
}
5349-
if (N > 24 || N < 0) {
5349+
if (!(N <= 24 && N >= 0)) {
53505350
RETURN_FALSE;
53515351
}
53525352

ext/date/tests/gh18481.phpt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-18481 (date_sunrise with utcOffset as INF)
3+
--FILE--
4+
<?php
5+
6+
foreach ([-NAN, NAN, INF, -INF] as $offset) {
7+
var_dump(date_sunrise(time(), SUNFUNCS_RET_STRING, 38.4, -9, 90, $offset));
8+
}
9+
?>
10+
--EXPECTF--
11+
Deprecated: Function date_sunrise() is deprecated in %s on line %d
12+
bool(false)
13+
14+
Deprecated: Function date_sunrise() is deprecated in %s on line %d
15+
bool(false)
16+
17+
Deprecated: Function date_sunrise() is deprecated in %s on line %d
18+
bool(false)
19+
20+
Deprecated: Function date_sunrise() is deprecated in %s on line %d
21+
bool(false)

0 commit comments

Comments
 (0)