Skip to content

Commit 9c07b42

Browse files
committed
Added PHP_DATE_DOUBLE_FITS_LONG similar to ZEND_DOUBLE_FITS_LONG
1 parent 1781833 commit 9c07b42

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

ext/date/php_date.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,15 +2510,15 @@ PHPAPI void php_date_initialize_from_ts_long(php_date_obj *dateobj, zend_long se
25102510
php_date_set_time_fraction(dateobj->time, usec);
25112511
} /* }}} */
25122512

2513+
25132514
PHPAPI bool php_date_initialize_from_ts_double(php_date_obj *dateobj, double ts) /* {{{ */
25142515
{
25152516
double sec_dval = trunc(ts);
25162517
zend_long sec = (zend_long)sec_dval;
25172518
int usec = (int)(fmod(ts, 1) * 1000000);
25182519

25192520
if (UNEXPECTED(isnan(sec_dval)
2520-
|| sec_dval > (double)TIMELIB_LONG_MAX
2521-
|| sec_dval < (double)TIMELIB_LONG_MIN
2521+
|| !PHP_DATE_DOUBLE_FITS_LONG(sec_dval)
25222522
|| (sec == TIMELIB_LONG_MIN && usec < 0)
25232523
)) {
25242524
zend_throw_error(

ext/date/php_date.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
#include "lib/timelib.h"
2121
#include "Zend/zend_hash.h"
2222

23+
/* Same as ZEND_DOUBLE_FITS_LONG but using TIMELIB_LONG_MAX/MIN */
24+
#if SIZEOF_TIMELIB_LONG == 4
25+
# define PHP_DATE_DOUBLE_FITS_LONG(d) (!((d) > (double)TIMELIB_LONG_MAX || (d) < (double)TIMELIB_LONG_MIN))
26+
#else
27+
/* >= as (double)TIMELIB_LONG_MAX is outside signed range */
28+
# define PHP_DATE_DOUBLE_FITS_LONG(d) (!((d) >= (double)TIMELIB_LONG_MAX || (d) < (double)TIMELIB_LONG_MIN))
29+
#endif
30+
2331
#include "php_version.h"
2432
#define PHP_DATE_VERSION PHP_VERSION
2533

0 commit comments

Comments
 (0)