Convert UNKNOWN default values to null in ext/calendar

This commit is contained in:
Máté Kocsis 2020-05-01 20:49:55 +02:00
parent 8a41c9e025
commit 089d8cb03c
No known key found for this signature in database
GPG key ID: FD055E41728BF310
5 changed files with 19 additions and 20 deletions

View file

@ -25,14 +25,15 @@
Convert UNIX timestamp to Julian Day */
PHP_FUNCTION(unixtojd)
{
time_t ts = 0;
time_t ts;
zend_bool ts_is_null = 1;
struct tm *ta, tmbuf;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &ts) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &ts, &ts_is_null) == FAILURE) {
RETURN_THROWS();
}
if (!ts) {
if (ts_is_null) {
ts = time(NULL);
} else if (ts < 0) {
zend_argument_value_error(1, "must be greater than or equal to 0");

View file

@ -192,14 +192,12 @@ PHP_FUNCTION(cal_info)
return;
}
if (cal != -1 && (cal < 0 || cal >= CAL_NUM_CALS)) {
if (cal < 0 || cal >= CAL_NUM_CALS) {
zend_argument_value_error(1, "must be a valid calendar ID");
RETURN_THROWS();
}
_php_cal_info(cal, return_value);
}
/* }}} */

View file

@ -6,13 +6,13 @@ function cal_days_in_month(int $calendar, int $month, int $year): int {}
function cal_from_jd(int $jd, int $calendar): array {}
function cal_info(?int $calendar = UNKNOWN): array {}
function cal_info(int $calendar = -1): array {}
function cal_to_jd(int $calendar, int $month, int $day, int $year): int {}
function easter_date(int $year = UNKNOWN, int $method = CAL_EASTER_DEFAULT): int {}
function easter_date(?int $year = null, int $method = CAL_EASTER_DEFAULT): int {}
function easter_days(int $year = UNKNOWN, int $method = CAL_EASTER_DEFAULT): int {}
function easter_days(?int $year = null, int $method = CAL_EASTER_DEFAULT): int {}
function frenchtojd(int $month, int $day, int $year): int {}
@ -36,4 +36,4 @@ function jewishtojd(int $month, int $day, int $year): int {}
function juliantojd(int $month, int $day, int $year): int {}
function unixtojd(int $timestamp = UNKNOWN): int|false {}
function unixtojd(?int $timestamp = null): int|false {}

View file

@ -12,7 +12,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_from_jd, 0, 2, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_info, 0, 0, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, calendar, IS_LONG, 1)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, calendar, IS_LONG, 0, "-1")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_to_jd, 0, 4, IS_LONG, 0)
@ -23,7 +23,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_to_jd, 0, 4, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_easter_date, 0, 0, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, year, IS_LONG, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, year, IS_LONG, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, method, IS_LONG, 0, "CAL_EASTER_DEFAULT")
ZEND_END_ARG_INFO()
@ -70,7 +70,7 @@ ZEND_END_ARG_INFO()
#define arginfo_juliantojd arginfo_frenchtojd
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_unixtojd, 0, 0, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()

View file

@ -23,15 +23,20 @@
static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, zend_long gm)
{
/* based on code by Simon Kershaw, <webmaster@ely.anglican.org> */
struct tm te;
zend_long year, golden, solar, lunar, pfm, dom, tmp, easter, result;
zend_long method = CAL_EASTER_DEFAULT;
zend_bool year_is_null = 1;
if (zend_parse_parameters(ZEND_NUM_ARGS(),
"|l!l", &year, &year_is_null, &method) == FAILURE) {
RETURN_THROWS();
}
/* Default to the current year if year parameter is not given */
{
if (year_is_null) {
time_t a;
struct tm b, *res;
time(&a);
@ -43,11 +48,6 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, zend_long gm)
}
}
if (zend_parse_parameters(ZEND_NUM_ARGS(),
"|ll", &year, &method) == FAILURE) {
RETURN_THROWS();
}
if (gm && (year<1970 || year>2037)) { /* out of range for timestamps */
zend_argument_value_error(1, "must be between 1970 and 2037 (inclusive)");
RETURN_THROWS();