-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/calendar: Allow easter_date to process years after 2037 on 64bit systems #11862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
| Authors: Shane Caraveo <[email protected]> | | ||
| Colin Viebrock <[email protected]> | | ||
| Hartmut Holzgraefe <[email protected]> | | ||
| Arne Perschke <[email protected]> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
|
@@ -21,6 +22,10 @@ | |
#include "sdncal.h" | ||
#include <time.h> | ||
|
||
/** | ||
* If `gm` is true this will return the timestamp at midnight on Easter of the given year. If it is false this | ||
* will return the number of days Easter is after March 21st. | ||
*/ | ||
static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, bool gm) | ||
{ | ||
/* based on code by Simon Kershaw, <[email protected]> */ | ||
|
@@ -48,10 +53,27 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, bool gm) | |
} | ||
} | ||
|
||
if (gm && (year<1970 || year>2037)) { /* out of range for timestamps */ | ||
#ifdef ZEND_ENABLE_ZVAL_LONG64 | ||
/* Compiling for 64bit, allow years between 1970 and 2.000.000.000 */ | ||
if (gm && year < 1970) { | ||
/* timestamps only start after 1970 */ | ||
zend_argument_value_error(1, "must be a year after 1970 (inclusive)"); | ||
RETURN_THROWS(); | ||
} | ||
|
||
if (gm && year > 2000000000) { | ||
/* timestamps only go up to the year 2.000.000.000 */ | ||
zend_argument_value_error(1, "must be a year before 2.000.000.000 (inclusive)"); | ||
RETURN_THROWS(); | ||
} | ||
#else | ||
/* Compiling for 32bit, allow years between 1970 and 2037 */ | ||
if (gm && (year < 1970 || year > 2037)) { | ||
zend_argument_value_error(1, "must be between 1970 and 2037 (inclusive)"); | ||
RETURN_THROWS(); | ||
} | ||
#endif | ||
|
||
|
||
golden = (year % 19) + 1; /* the Golden number */ | ||
|
||
|
4 changes: 3 additions & 1 deletion
4
ext/calendar/tests/easter_date.phpt → ext/calendar/tests/easter_date_32bit.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--TEST-- | ||
Test easter_date() on 64bit systems | ||
--SKIPIF-- | ||
<?php if (PHP_INT_SIZE != 8) die("skip 64-bit only"); ?> | ||
--INI-- | ||
date.timezone=UTC | ||
--ENV-- | ||
TZ=UTC | ||
--EXTENSIONS-- | ||
calendar | ||
--FILE-- | ||
<?php | ||
putenv('TZ=UTC'); | ||
echo date("Y-m-d", easter_date(2000))."\n"; | ||
echo date("Y-m-d", easter_date(2001))."\n"; | ||
echo date("Y-m-d", easter_date(2002))."\n"; | ||
echo date("Y-m-d", easter_date(2045))."\n"; | ||
echo date("Y-m-d", easter_date(2046))."\n"; | ||
echo date("Y-m-d", easter_date(2047))."\n"; | ||
try { | ||
easter_date(1492); | ||
} catch (ValueError $ex) { | ||
echo "{$ex->getMessage()}\n"; | ||
} | ||
?> | ||
--EXPECT-- | ||
2000-04-23 | ||
2001-04-15 | ||
2002-03-31 | ||
2045-04-09 | ||
2046-03-25 | ||
2047-04-14 | ||
easter_date(): Argument #1 ($year) must be a year after 1970 (inclusive) |
21 changes: 21 additions & 0 deletions
21
ext/calendar/tests/easter_date_checks_upper_bound_32bit.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
Test easter_date() on 32bit systems checks the upper year limit | ||
--SKIPIF-- | ||
<?php if (PHP_INT_SIZE != 4) die("skip 32-bit only"); ?> | ||
--INI-- | ||
date.timezone=UTC | ||
--ENV-- | ||
TZ=UTC | ||
--EXTENSIONS-- | ||
calendar | ||
--FILE-- | ||
<?php | ||
putenv('TZ=UTC'); | ||
try { | ||
easter_date(2040); | ||
} catch (ValueError $ex) { | ||
echo "{$ex->getMessage()}\n"; | ||
} | ||
?> | ||
--EXPECT-- | ||
easter_date(): Argument #1 ($year) must be between 1970 and 2037 (inclusive) |
21 changes: 21 additions & 0 deletions
21
ext/calendar/tests/easter_date_checks_upper_bound_64bit.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
Test easter_date() on 64bit systems checks the upper year limit | ||
--SKIPIF-- | ||
<?php if (PHP_INT_SIZE != 8) die("skip 64-bit only"); ?> | ||
--INI-- | ||
date.timezone=UTC | ||
--ENV-- | ||
TZ=UTC | ||
--EXTENSIONS-- | ||
calendar | ||
--FILE-- | ||
<?php | ||
putenv('TZ=UTC'); | ||
try { | ||
easter_date(293274701009); | ||
} catch (ValueError $ex) { | ||
echo "{$ex->getMessage()}\n"; | ||
} | ||
?> | ||
--EXPECT-- | ||
easter_date(): Argument #1 ($year) must be a year before 2.000.000.000 (inclusive) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We list these in alphabetical order, but that can be fixed as a follow-up for now