File tree Expand file tree Collapse file tree 4 files changed +52
-4
lines changed Expand file tree Collapse file tree 4 files changed +52
-4
lines changed Original file line number Diff line number Diff line change 21
21
#include "sdncal.h"
22
22
#include <time.h>
23
23
24
+ #define SECS_PER_DAY (24 * 3600)
25
+
24
26
/* {{{ Convert UNIX timestamp to Julian Day */
25
27
PHP_FUNCTION (unixtojd )
26
28
{
@@ -60,11 +62,11 @@ PHP_FUNCTION(jdtounix)
60
62
}
61
63
uday -= 2440588 /* J.D. of 1.1.1970 */ ;
62
64
63
- if (uday < 0 || uday > 24755 ) {
64
- zend_value_error ("jday must be within the Unix epoch" );
65
+ if (uday < 0 || uday > ZEND_LONG_MAX / SECS_PER_DAY ) { /* before beginning of unix epoch or greater than representable */
66
+ zend_value_error ("jday must be between 2440588 and " ZEND_LONG_FMT , ZEND_LONG_MAX / SECS_PER_DAY + 2440588 );
65
67
RETURN_THROWS ();
66
68
}
67
69
68
- RETURN_LONG (uday * 24 * 3600 );
70
+ RETURN_LONG (uday * SECS_PER_DAY );
69
71
}
70
72
/* }}} */
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug #80185 (jdtounix() fails after 2037)
3
+ --SKIPIF--
4
+ <?php
5
+ if (!extension_loaded ('calendar ' )) die ('skip ext/calendar required ' );
6
+ if (PHP_INT_SIZE != 8 ) die ("skip for 64bit platforms only " );
7
+ ?>
8
+ --FILE--
9
+ <?php
10
+ var_dump (jdtounix (2465712 ));
11
+ var_dump (jdtounix (PHP_INT_MAX / 86400 + 2440588 ));
12
+ try {
13
+ var_dump (jdtounix (PHP_INT_MAX / 86400 + 2440589 ));
14
+ } catch (ValueError $ ex ) {
15
+ echo $ ex ->getMessage (), PHP_EOL ;
16
+ }
17
+ ?>
18
+ --EXPECT--
19
+ int(2170713600)
20
+ int(9223372036854720000)
21
+ jday must be between 2440588 and 106751993607888
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug #80185 (jdtounix() fails after 2037)
3
+ --SKIPIF--
4
+ <?php
5
+ if (!extension_loaded ('calendar ' )) die ('skip ext/calendar required ' );
6
+ if (PHP_INT_SIZE != 4 ) die ("skip for 32bit platforms only " );
7
+ ?>
8
+ --FILE--
9
+ <?php
10
+ try {
11
+ var_dump (jdtounix (2465712 ));
12
+ } catch (ValueError $ ex ) {
13
+ echo $ ex ->getMessage (), PHP_EOL ;
14
+ }
15
+ var_dump (jdtounix (PHP_INT_MAX / 86400 + 2440588 ));
16
+ try {
17
+ var_dump (jdtounix (PHP_INT_MAX / 86400 + 2440589 ));
18
+ } catch (ValueError $ ex ) {
19
+ echo $ ex ->getMessage (), PHP_EOL ;
20
+ }
21
+ ?>
22
+ --EXPECT--
23
+ jday must be between 2440588 and 2465443
24
+ int(2147472000)
25
+ jday must be between 2440588 and 2465443
Original file line number Diff line number Diff line change 15
15
}
16
16
?>
17
17
--EXPECT--
18
- jday must be within the Unix epoch
18
+ jday must be between 2440588 and 2465443
You can’t perform that action at this time.
0 commit comments