summaryrefslogtreecommitdiff
path: root/ext/date/php_date.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/date/php_date.c')
-rw-r--r--ext/date/php_date.c429
1 files changed, 224 insertions, 205 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 813f8663f0..f2ced7bd59 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
@@ -39,6 +39,24 @@ static __inline __int64_t php_date_llabs( __int64_t i ) { return i >= 0 ? i : -i
static inline long long php_date_llabs( long long i ) { return i >= 0 ? i : -i; }
#endif
+#ifdef PHP_WIN32
+#define DATE_I64_BUF_LEN 65
+# define DATE_I64A(i, s, len) _i64toa_s(i, s, len, 10)
+# define DATE_A64I(i, s) i = _atoi64(s)
+#else
+#define DATE_I64_BUF_LEN 65
+# define DATE_I64A(i, s, len) \
+ do { \
+ int st = snprintf(s, len, "%lld", i); \
+ s[st] = '\0'; \
+ } while (0);
+#ifdef HAVE_ATOLL
+# define DATE_A64I(i, s) i = atoll(s)
+#else
+# define DATE_A64I(i, s) i = strtoll(s, NULL, 10)
+#endif
+#endif
+
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX(arginfo_date, 0, 0, 1)
ZEND_ARG_INFO(0, format)
@@ -307,12 +325,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_name_from_abbr, 0, 0, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_offset_get, 0, 0, 2)
- ZEND_ARG_INFO(0, object)
- ZEND_ARG_INFO(0, datetime)
+ ZEND_ARG_OBJ_INFO(0, object, DateTimeZone, 0)
+ ZEND_ARG_OBJ_INFO(0, datetime, DateTimeInterface, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_method_offset_get, 0, 0, 1)
- ZEND_ARG_INFO(0, datetime)
+ ZEND_ARG_INFO(0, object)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_transitions_get, 0, 0, 1)
@@ -842,9 +860,9 @@ PHP_MINIT_FUNCTION(date)
REGISTER_STRING_CONSTANT("DATE_RSS", DATE_FORMAT_RFC1123, CONST_CS | CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("DATE_W3C", DATE_FORMAT_RFC3339, CONST_CS | CONST_PERSISTENT);
- REGISTER_INT_CONSTANT("SUNFUNCS_RET_TIMESTAMP", SUNFUNCS_RET_TIMESTAMP, CONST_CS | CONST_PERSISTENT);
- REGISTER_INT_CONSTANT("SUNFUNCS_RET_STRING", SUNFUNCS_RET_STRING, CONST_CS | CONST_PERSISTENT);
- REGISTER_INT_CONSTANT("SUNFUNCS_RET_DOUBLE", SUNFUNCS_RET_DOUBLE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("SUNFUNCS_RET_TIMESTAMP", SUNFUNCS_RET_TIMESTAMP, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("SUNFUNCS_RET_STRING", SUNFUNCS_RET_STRING, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("SUNFUNCS_RET_DOUBLE", SUNFUNCS_RET_DOUBLE, CONST_CS | CONST_PERSISTENT);
php_date_global_timezone_db = NULL;
php_date_global_timezone_db_enabled = 0;
@@ -914,7 +932,7 @@ timelib_tzinfo *php_date_parse_tzfile_wrapper(char *formal_tzname, const timelib
/* {{{ static PHP_INI_MH(OnUpdate_date_timezone) */
static PHP_INI_MH(OnUpdate_date_timezone)
{
- if (OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC) == FAILURE) {
+ if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC) == FAILURE) {
return FAILURE;
}
@@ -941,11 +959,11 @@ static char* guess_timezone(const timelib_tzdb *tzdb TSRMLS_DC)
/* Check config setting for default timezone */
if (!DATEG(default_timezone)) {
/* Special case: ext/date wasn't initialized yet */
- zval ztz;
+ zval *ztz;
- if (SUCCESS == zend_get_configuration_directive("date.timezone", sizeof("date.timezone"), &ztz)
- && Z_TYPE(ztz) == IS_STRING && Z_STRSIZE(ztz) > 0 && timelib_timezone_id_is_valid(Z_STRVAL(ztz), tzdb)) {
- return Z_STRVAL(ztz);
+ if (NULL != (ztz = cfg_get_entry("date.timezone", sizeof("date.timezone")))
+ && Z_TYPE_P(ztz) == IS_STRING && Z_STRLEN_P(ztz) > 0 && timelib_timezone_id_is_valid(Z_STRVAL_P(ztz), tzdb)) {
+ return Z_STRVAL_P(ztz);
}
} else if (*DATEG(default_timezone)) {
if (DATEG(timezone_valid) == 1) {
@@ -981,7 +999,7 @@ PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D)
/* {{{ date() and gmdate() data */
-#include "ext/standard/php_smart_str.h"
+#include "zend_smart_str.h"
static char *mon_full_names[] = {
"January", "February", "March", "April",
@@ -1037,7 +1055,7 @@ char *php_date_short_day_name(timelib_sll y, timelib_sll m, timelib_sll d)
/* }}} */
/* {{{ date_format - (gm)date helper */
-static zend_string *date_format(char *format, int format_len, timelib_time *t, int localtime TSRMLS_DC)
+static zend_string *date_format(char *format, size_t format_len, timelib_time *t, int localtime TSRMLS_DC)
{
smart_str string = {0};
int i, length = 0;
@@ -1198,10 +1216,10 @@ static zend_string *date_format(char *format, int format_len, timelib_time *t, i
static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime)
{
char *format;
- int format_len;
- php_int_t ts;
+ size_t format_len;
+ zend_long ts;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|i", &format, &format_len, &ts) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &format, &format_len, &ts) == FAILURE) {
RETURN_FALSE;
}
if (ZEND_NUM_ARGS() == 1) {
@@ -1354,11 +1372,11 @@ PHP_FUNCTION(gmdate)
PHP_FUNCTION(idate)
{
char *format;
- int format_len;
- php_int_t ts = 0;
+ size_t format_len;
+ zend_long ts = 0;
int ret;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|i", &format, &format_len, &ts) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &format, &format_len, &ts) == FAILURE) {
RETURN_FALSE;
}
@@ -1376,7 +1394,7 @@ PHP_FUNCTION(idate)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unrecognized date format token.");
RETURN_FALSE;
}
- RETURN_INT(ret);
+ RETURN_LONG(ret);
}
/* }}} */
@@ -1393,12 +1411,12 @@ PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb)
/* }}} */
/* {{{ php_parse_date: Backwards compatibility function */
-PHPAPI php_int_t php_parse_date(char *string, php_int_t *now)
+PHPAPI zend_long php_parse_date(char *string, zend_long *now)
{
timelib_time *parsed_time;
timelib_error_container *error = NULL;
int error2;
- php_int_t retval;
+ zend_long retval;
parsed_time = timelib_strtotime(string, strlen(string), &error, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
if (error->error_count) {
@@ -1422,21 +1440,22 @@ PHPAPI php_int_t php_parse_date(char *string, php_int_t *now)
PHP_FUNCTION(strtotime)
{
char *times, *initial_ts;
- int time_len, error1, error2;
+ size_t time_len;
+ int error1, error2;
struct timelib_error_container *error;
- php_int_t preset_ts = 0, ts;
+ zend_long preset_ts = 0, ts;
timelib_time *t, *now;
timelib_tzinfo *tzi;
tzi = get_timezone_info(TSRMLS_C);
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "si", &times, &time_len, &preset_ts) != FAILURE) {
+ if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "sl", &times, &time_len, &preset_ts) != FAILURE) {
/* We have an initial timestamp */
now = timelib_time_ctor();
initial_ts = emalloc(25);
- snprintf(initial_ts, 24, "@%ld UTC", preset_ts);
+ snprintf(initial_ts, 24, "@" ZEND_LONG_FMT " UTC", preset_ts);
t = timelib_strtotime(initial_ts, strlen(initial_ts), NULL, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper); /* we ignore the error here, as this should never fail */
timelib_update_ts(t, tzi);
now->tz_info = tzi;
@@ -1444,7 +1463,7 @@ PHP_FUNCTION(strtotime)
timelib_unixtime2local(now, t->sse);
timelib_time_dtor(t);
efree(initial_ts);
- } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|i", &times, &time_len, &preset_ts) != FAILURE) {
+ } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &times, &time_len, &preset_ts) != FAILURE) {
/* We have no initial timestamp */
now = timelib_time_ctor();
now->tz_info = tzi;
@@ -1472,7 +1491,7 @@ PHP_FUNCTION(strtotime)
if (error1 || error2) {
RETURN_FALSE;
} else {
- RETURN_INT(ts);
+ RETURN_LONG(ts);
}
}
/* }}} */
@@ -1480,13 +1499,13 @@ PHP_FUNCTION(strtotime)
/* {{{ php_mktime - (gm)mktime helper */
PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
{
- php_int_t hou = 0, min = 0, sec = 0, mon = 0, day = 0, yea = 0, dst = -1;
+ zend_long hou = 0, min = 0, sec = 0, mon = 0, day = 0, yea = 0, dst = -1;
timelib_time *now;
timelib_tzinfo *tzi = NULL;
- php_int_t ts, adjust_seconds = 0;
+ zend_long ts, adjust_seconds = 0;
int error;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|iiiiiii", &hou, &min, &sec, &mon, &day, &yea, &dst) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lllllll", &hou, &min, &sec, &mon, &day, &yea, &dst) == FAILURE) {
RETURN_FALSE;
}
/* Initialize structure with current time */
@@ -1564,7 +1583,7 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
if (error) {
RETURN_FALSE;
} else {
- RETURN_INT(ts);
+ RETURN_LONG(ts);
}
}
/* }}} */
@@ -1589,9 +1608,9 @@ PHP_FUNCTION(gmmktime)
Returns true(1) if it is a valid date in gregorian calendar */
PHP_FUNCTION(checkdate)
{
- php_int_t m, d, y;
+ zend_long m, d, y;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "iii", &m, &d, &y) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &m, &d, &y) == FAILURE) {
RETURN_FALSE;
}
@@ -1607,8 +1626,8 @@ PHP_FUNCTION(checkdate)
PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
{
char *format;
- int format_len;
- php_int_t timestamp = 0;
+ size_t format_len;
+ zend_long timestamp = 0;
struct tm ta;
int max_reallocs = 5;
size_t buf_len = 256, real_len;
@@ -1617,9 +1636,9 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
timelib_time_offset *offset = NULL;
zend_string *buf;
- timestamp = (php_int_t) time(NULL);
+ timestamp = (zend_long) time(NULL);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|i", &format, &format_len, &timestamp) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &format, &format_len, &timestamp) == FAILURE) {
RETURN_FALSE;
}
@@ -1668,10 +1687,10 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
/* VS2012 crt has a bug where strftime crash with %z and %Z format when the
initial buffer is too small. See
http://connect.microsoft.com/VisualStudio/feedback/details/759720/vs2012-strftime-crash-with-z-formatting-code */
- buf = STR_ALLOC(buf_len, 0);
+ buf = zend_string_alloc(buf_len, 0);
while ((real_len = strftime(buf->val, buf_len, format, &ta)) == buf_len || real_len == 0) {
buf_len *= 2;
- buf = STR_REALLOC(buf, buf_len, 0);
+ buf = zend_string_realloc(buf, buf_len, 0);
if (!--max_reallocs) {
break;
}
@@ -1690,10 +1709,10 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
}
if (real_len && real_len != buf_len) {
- buf = STR_REALLOC(buf, real_len, 0);
+ buf = zend_string_realloc(buf, real_len, 0);
RETURN_STR(buf);
}
- STR_FREE(buf);
+ zend_string_free(buf);
RETURN_FALSE;
}
/* }}} */
@@ -1719,7 +1738,7 @@ PHP_FUNCTION(gmstrftime)
Return current UNIX timestamp */
PHP_FUNCTION(time)
{
- RETURN_INT((php_int_t)time(NULL));
+ RETURN_LONG((zend_long)time(NULL));
}
/* }}} */
@@ -1727,12 +1746,12 @@ PHP_FUNCTION(time)
Returns the results of the C system call localtime as an associative array if the associative_array argument is set to 1 other wise it is a regular array */
PHP_FUNCTION(localtime)
{
- php_int_t timestamp = (php_int_t)time(NULL);
+ zend_long timestamp = (zend_long)time(NULL);
zend_bool associative = 0;
timelib_tzinfo *tzi;
timelib_time *ts;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ib", &timestamp, &associative) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", &timestamp, &associative) == FAILURE) {
RETURN_FALSE;
}
@@ -1745,25 +1764,25 @@ PHP_FUNCTION(localtime)
array_init(return_value);
if (associative) {
- add_assoc_int(return_value, "tm_sec", ts->s);
- add_assoc_int(return_value, "tm_min", ts->i);
- add_assoc_int(return_value, "tm_hour", ts->h);
- add_assoc_int(return_value, "tm_mday", ts->d);
- add_assoc_int(return_value, "tm_mon", ts->m - 1);
- add_assoc_int(return_value, "tm_year", ts->y - 1900);
- add_assoc_int(return_value, "tm_wday", timelib_day_of_week(ts->y, ts->m, ts->d));
- add_assoc_int(return_value, "tm_yday", timelib_day_of_year(ts->y, ts->m, ts->d));
- add_assoc_int(return_value, "tm_isdst", ts->dst);
+ add_assoc_long(return_value, "tm_sec", ts->s);
+ add_assoc_long(return_value, "tm_min", ts->i);
+ add_assoc_long(return_value, "tm_hour", ts->h);
+ add_assoc_long(return_value, "tm_mday", ts->d);
+ add_assoc_long(return_value, "tm_mon", ts->m - 1);
+ add_assoc_long(return_value, "tm_year", ts->y - 1900);
+ add_assoc_long(return_value, "tm_wday", timelib_day_of_week(ts->y, ts->m, ts->d));
+ add_assoc_long(return_value, "tm_yday", timelib_day_of_year(ts->y, ts->m, ts->d));
+ add_assoc_long(return_value, "tm_isdst", ts->dst);
} else {
- add_next_index_int(return_value, ts->s);
- add_next_index_int(return_value, ts->i);
- add_next_index_int(return_value, ts->h);
- add_next_index_int(return_value, ts->d);
- add_next_index_int(return_value, ts->m - 1);
- add_next_index_int(return_value, ts->y- 1900);
- add_next_index_int(return_value, timelib_day_of_week(ts->y, ts->m, ts->d));
- add_next_index_int(return_value, timelib_day_of_year(ts->y, ts->m, ts->d));
- add_next_index_int(return_value, ts->dst);
+ add_next_index_long(return_value, ts->s);
+ add_next_index_long(return_value, ts->i);
+ add_next_index_long(return_value, ts->h);
+ add_next_index_long(return_value, ts->d);
+ add_next_index_long(return_value, ts->m - 1);
+ add_next_index_long(return_value, ts->y- 1900);
+ add_next_index_long(return_value, timelib_day_of_week(ts->y, ts->m, ts->d));
+ add_next_index_long(return_value, timelib_day_of_year(ts->y, ts->m, ts->d));
+ add_next_index_long(return_value, ts->dst);
}
timelib_time_dtor(ts);
@@ -1774,11 +1793,11 @@ PHP_FUNCTION(localtime)
Get date/time information */
PHP_FUNCTION(getdate)
{
- php_int_t timestamp = (php_int_t)time(NULL);
+ zend_long timestamp = (zend_long)time(NULL);
timelib_tzinfo *tzi;
timelib_time *ts;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|i", &timestamp) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &timestamp) == FAILURE) {
RETURN_FALSE;
}
@@ -1790,17 +1809,17 @@ PHP_FUNCTION(getdate)
array_init(return_value);
- add_assoc_int(return_value, "seconds", ts->s);
- add_assoc_int(return_value, "minutes", ts->i);
- add_assoc_int(return_value, "hours", ts->h);
- add_assoc_int(return_value, "mday", ts->d);
- add_assoc_int(return_value, "wday", timelib_day_of_week(ts->y, ts->m, ts->d));
- add_assoc_int(return_value, "mon", ts->m);
- add_assoc_int(return_value, "year", ts->y);
- add_assoc_int(return_value, "yday", timelib_day_of_year(ts->y, ts->m, ts->d));
+ add_assoc_long(return_value, "seconds", ts->s);
+ add_assoc_long(return_value, "minutes", ts->i);
+ add_assoc_long(return_value, "hours", ts->h);
+ add_assoc_long(return_value, "mday", ts->d);
+ add_assoc_long(return_value, "wday", timelib_day_of_week(ts->y, ts->m, ts->d));
+ add_assoc_long(return_value, "mon", ts->m);
+ add_assoc_long(return_value, "year", ts->y);
+ add_assoc_long(return_value, "yday", timelib_day_of_year(ts->y, ts->m, ts->d));
add_assoc_string(return_value, "weekday", php_date_full_day_name(ts->y, ts->m, ts->d));
add_assoc_string(return_value, "month", mon_full_names[ts->m - 1]);
- add_index_int(return_value, 0, timestamp);
+ add_index_long(return_value, 0, timestamp);
timelib_time_dtor(ts);
}
@@ -1907,7 +1926,7 @@ static zval *date_period_it_current_data(zend_object_iterator *iter TSRMLS_DC)
static void date_period_it_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC)
{
date_period_it *iterator = (date_period_it *)iter;
- ZVAL_INT(key, iterator->current_index);
+ ZVAL_LONG(key, iterator->current_index);
}
/* }}} */
@@ -2031,7 +2050,7 @@ static void date_register_classes(TSRMLS_D) /* {{{ */
date_object_handlers_timezone.get_gc = date_object_get_gc_timezone;
#define REGISTER_TIMEZONE_CLASS_CONST_STRING(const_name, value) \
- zend_declare_class_constant_int(date_ce_timezone, const_name, sizeof(const_name)-1, value TSRMLS_CC);
+ zend_declare_class_constant_long(date_ce_timezone, const_name, sizeof(const_name)-1, value TSRMLS_CC);
REGISTER_TIMEZONE_CLASS_CONST_STRING("AFRICA", PHP_DATE_TIMEZONE_GROUP_AFRICA);
REGISTER_TIMEZONE_CLASS_CONST_STRING("AMERICA", PHP_DATE_TIMEZONE_GROUP_AMERICA);
@@ -2078,7 +2097,7 @@ static void date_register_classes(TSRMLS_D) /* {{{ */
date_object_handlers_period.write_property = date_period_write_property;
#define REGISTER_PERIOD_CLASS_CONST_STRING(const_name, value) \
- zend_declare_class_constant_int(date_ce_period, const_name, sizeof(const_name)-1, value TSRMLS_CC);
+ zend_declare_class_constant_long(date_ce_period, const_name, sizeof(const_name)-1, value TSRMLS_CC);
REGISTER_PERIOD_CLASS_CONST_STRING("EXCLUDE_START_DATE", PHP_DATE_PERIOD_EXCLUDE_START_DATE);
} /* }}} */
@@ -2185,7 +2204,7 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC) /* {{{ */
/* then we add the timezone name (or similar) */
if (dateobj->time->is_localtime) {
- ZVAL_INT(&zv, dateobj->time->zone_type);
+ ZVAL_LONG(&zv, dateobj->time->zone_type);
zend_hash_str_update(props, "timezone_type", sizeof("timezone_type")-1, &zv);
switch (dateobj->time->zone_type) {
@@ -2193,7 +2212,7 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC) /* {{{ */
ZVAL_STRING(&zv, dateobj->time->tz_info->name);
break;
case TIMELIB_ZONETYPE_OFFSET: {
- zend_string *tmpstr = STR_ALLOC(sizeof("UTC+05:00")-1, 0);
+ zend_string *tmpstr = zend_string_alloc(sizeof("UTC+05:00")-1, 0);
timelib_sll utc_offset = dateobj->time->z;
tmpstr->len = snprintf(tmpstr->val, sizeof("+05:00"), "%c%02d:%02d",
@@ -2201,7 +2220,7 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC) /* {{{ */
abs(utc_offset / 60),
abs((utc_offset % 60)));
- ZVAL_STR(&zv, tmpstr);
+ ZVAL_NEW_STR(&zv, tmpstr);
}
break;
case TIMELIB_ZONETYPE_ABBR:
@@ -2278,7 +2297,7 @@ static HashTable *date_object_get_properties_timezone(zval *object TSRMLS_DC) /*
return props;
}
- ZVAL_INT(&zv, tzobj->type);
+ ZVAL_LONG(&zv, tzobj->type);
zend_hash_str_update(props, "timezone_type", sizeof("timezone_type")-1, &zv);
switch (tzobj->type) {
@@ -2286,14 +2305,14 @@ static HashTable *date_object_get_properties_timezone(zval *object TSRMLS_DC) /*
ZVAL_STRING(&zv, tzobj->tzi.tz->name);
break;
case TIMELIB_ZONETYPE_OFFSET: {
- zend_string *tmpstr = STR_ALLOC(sizeof("UTC+05:00")-1, 0);
+ zend_string *tmpstr = zend_string_alloc(sizeof("UTC+05:00")-1, 0);
tmpstr->len = snprintf(tmpstr->val, sizeof("+05:00"), "%c%02d:%02d",
tzobj->tzi.utc_offset > 0 ? '-' : '+',
abs(tzobj->tzi.utc_offset / 60),
abs((tzobj->tzi.utc_offset % 60)));
- ZVAL_STR(&zv, tmpstr);
+ ZVAL_NEW_STR(&zv, tmpstr);
}
break;
case TIMELIB_ZONETYPE_ABBR:
@@ -2359,7 +2378,7 @@ static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC) /*
}
#define PHP_DATE_INTERVAL_ADD_PROPERTY(n,f) \
- ZVAL_INT(&zv, (php_int_t)intervalobj->diff->f); \
+ ZVAL_LONG(&zv, (zend_long)intervalobj->diff->f); \
zend_hash_str_update(props, n, sizeof(n)-1, &zv);
PHP_DATE_INTERVAL_ADD_PROPERTY("y", y);
@@ -2485,7 +2504,7 @@ static void update_errors_warnings(timelib_error_container *last_errors TSRMLS_D
DATEG(last_errors) = last_errors;
} /* }}} */
-PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int time_str_len, char *format, zval *timezone_object, int ctor TSRMLS_DC) /* {{{ */
+PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, size_t time_str_len, char *format, zval *timezone_object, int ctor TSRMLS_DC) /* {{{ */
{
timelib_time *now;
timelib_tzinfo *tzi = NULL;
@@ -2577,7 +2596,7 @@ PHP_FUNCTION(date_create)
{
zval *timezone_object = NULL;
char *time_str = NULL;
- int time_str_len = 0;
+ size_t time_str_len = 0;
zval datetime_object;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
@@ -2600,7 +2619,7 @@ PHP_FUNCTION(date_create_immutable)
{
zval *timezone_object = NULL;
char *time_str = NULL;
- int time_str_len = 0;
+ size_t time_str_len = 0;
zval datetime_object;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
@@ -2623,7 +2642,7 @@ PHP_FUNCTION(date_create_from_format)
{
zval *timezone_object = NULL;
char *time_str = NULL, *format_str = NULL;
- int time_str_len = 0, format_str_len = 0;
+ size_t time_str_len = 0, format_str_len = 0;
zval datetime_object;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|O", &format_str, &format_str_len, &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
@@ -2646,7 +2665,7 @@ PHP_FUNCTION(date_create_immutable_from_format)
{
zval *timezone_object = NULL;
char *time_str = NULL, *format_str = NULL;
- int time_str_len = 0, format_str_len = 0;
+ size_t time_str_len = 0, format_str_len = 0;
zval datetime_object;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|O", &format_str, &format_str_len, &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
@@ -2669,7 +2688,7 @@ PHP_METHOD(DateTime, __construct)
{
zval *timezone_object = NULL;
char *time_str = NULL;
- int time_str_len = 0;
+ size_t time_str_len = 0;
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
@@ -2689,7 +2708,7 @@ PHP_METHOD(DateTimeImmutable, __construct)
{
zval *timezone_object = NULL;
char *time_str = NULL;
- int time_str_len = 0;
+ size_t time_str_len = 0;
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
@@ -2742,18 +2761,18 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
convert_to_string(z_date);
z_timezone_type = zend_hash_str_find(myht, "timezone_type", sizeof("timezone_type")-1);
if (z_timezone_type) {
- convert_to_int(z_timezone_type);
+ convert_to_long(z_timezone_type);
z_timezone = zend_hash_str_find(myht, "timezone", sizeof("timezone")-1);
if (z_timezone) {
convert_to_string(z_timezone);
- switch (Z_IVAL_P(z_timezone_type)) {
+ switch (Z_LVAL_P(z_timezone_type)) {
case TIMELIB_ZONETYPE_OFFSET:
case TIMELIB_ZONETYPE_ABBR: {
- char *tmp = emalloc(Z_STRSIZE_P(z_date) + Z_STRSIZE_P(z_timezone) + 2);
+ char *tmp = emalloc(Z_STRLEN_P(z_date) + Z_STRLEN_P(z_timezone) + 2);
int ret;
- snprintf(tmp, Z_STRSIZE_P(z_date) + Z_STRSIZE_P(z_timezone) + 2, "%s %s", Z_STRVAL_P(z_date), Z_STRVAL_P(z_timezone));
- ret = php_date_initialize(*dateobj, tmp, Z_STRSIZE_P(z_date) + Z_STRSIZE_P(z_timezone) + 1, NULL, NULL, 0 TSRMLS_CC);
+ snprintf(tmp, Z_STRLEN_P(z_date) + Z_STRLEN_P(z_timezone) + 2, "%s %s", Z_STRVAL_P(z_date), Z_STRVAL_P(z_timezone));
+ ret = php_date_initialize(*dateobj, tmp, Z_STRLEN_P(z_date) + Z_STRLEN_P(z_timezone) + 1, NULL, NULL, 0 TSRMLS_CC);
efree(tmp);
return 1 == ret;
}
@@ -2773,7 +2792,7 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
tzobj->tzi.tz = tzi;
tzobj->initialized = 1;
- ret = php_date_initialize(*dateobj, Z_STRVAL_P(z_date), Z_STRSIZE_P(z_date), NULL, &tmp_obj, 0 TSRMLS_CC);
+ ret = php_date_initialize(*dateobj, Z_STRVAL_P(z_date), Z_STRLEN_P(z_date), NULL, &tmp_obj, 0 TSRMLS_CC);
zval_ptr_dtor(&tmp_obj);
return 1 == ret;
}
@@ -2852,14 +2871,14 @@ static void zval_from_error_container(zval *z, timelib_error_container *error) /
int i;
zval element;
- add_assoc_int(z, "warning_count", error->warning_count);
+ add_assoc_long(z, "warning_count", error->warning_count);
array_init(&element);
for (i = 0; i < error->warning_count; i++) {
add_index_string(&element, error->warning_messages[i].position, error->warning_messages[i].message);
}
add_assoc_zval(z, "warnings", &element);
- add_assoc_int(z, "error_count", error->error_count);
+ add_assoc_long(z, "error_count", error->error_count);
array_init(&element);
for (i = 0; i < error->error_count; i++) {
add_index_string(&element, error->error_messages[i].position, error->error_messages[i].message);
@@ -2890,7 +2909,7 @@ void php_date_do_return_parsed_time(INTERNAL_FUNCTION_PARAMETERS, timelib_time *
if (parsed_time->elem == -99999) { \
add_assoc_bool(return_value, #name, 0); \
} else { \
- add_assoc_int(return_value, #name, parsed_time->elem); \
+ add_assoc_long(return_value, #name, parsed_time->elem); \
}
PHP_DATE_PARSE_DATE_SET_TIME_ELEMENT(year, y);
PHP_DATE_PARSE_DATE_SET_TIME_ELEMENT(month, m);
@@ -2935,17 +2954,17 @@ void php_date_do_return_parsed_time(INTERNAL_FUNCTION_PARAMETERS, timelib_time *
}
if (parsed_time->have_relative) {
array_init(&element);
- add_assoc_int(&element, "year", parsed_time->relative.y);
- add_assoc_int(&element, "month", parsed_time->relative.m);
- add_assoc_int(&element, "day", parsed_time->relative.d);
- add_assoc_int(&element, "hour", parsed_time->relative.h);
- add_assoc_int(&element, "minute", parsed_time->relative.i);
- add_assoc_int(&element, "second", parsed_time->relative.s);
+ add_assoc_long(&element, "year", parsed_time->relative.y);
+ add_assoc_long(&element, "month", parsed_time->relative.m);
+ add_assoc_long(&element, "day", parsed_time->relative.d);
+ add_assoc_long(&element, "hour", parsed_time->relative.h);
+ add_assoc_long(&element, "minute", parsed_time->relative.i);
+ add_assoc_long(&element, "second", parsed_time->relative.s);
if (parsed_time->relative.have_weekday_relative) {
- add_assoc_int(&element, "weekday", parsed_time->relative.weekday);
+ add_assoc_long(&element, "weekday", parsed_time->relative.weekday);
}
if (parsed_time->relative.have_special_relative && (parsed_time->relative.special.type == TIMELIB_SPECIAL_WEEKDAY)) {
- add_assoc_int(&element, "weekdays", parsed_time->relative.special.amount);
+ add_assoc_long(&element, "weekdays", parsed_time->relative.special.amount);
}
if (parsed_time->relative.first_last_day_of) {
add_assoc_bool(&element, parsed_time->relative.first_last_day_of == 1 ? "first_day_of_month" : "last_day_of_month", 1);
@@ -2961,7 +2980,7 @@ void php_date_do_return_parsed_time(INTERNAL_FUNCTION_PARAMETERS, timelib_time *
PHP_FUNCTION(date_parse)
{
char *date;
- int date_len;
+ size_t date_len;
struct timelib_error_container *error;
timelib_time *parsed_time;
@@ -2980,7 +2999,7 @@ PHP_FUNCTION(date_parse)
PHP_FUNCTION(date_parse_from_format)
{
char *date, *format;
- int date_len, format_len;
+ size_t date_len, format_len;
struct timelib_error_container *error;
timelib_time *parsed_time;
@@ -3001,7 +3020,7 @@ PHP_FUNCTION(date_format)
zval *object;
php_date_obj *dateobj;
char *format;
- int format_len;
+ size_t format_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, date_ce_interface, &format, &format_len) == FAILURE) {
RETURN_FALSE;
@@ -3081,7 +3100,7 @@ PHP_FUNCTION(date_modify)
{
zval *object;
char *modify;
- int modify_len;
+ size_t modify_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, date_ce_date, &modify, &modify_len) == FAILURE) {
RETURN_FALSE;
@@ -3101,7 +3120,7 @@ PHP_METHOD(DateTimeImmutable, modify)
{
zval *object, new_object;
char *modify;
- int modify_len;
+ size_t modify_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, date_ce_immutable, &modify, &modify_len) == FAILURE) {
RETURN_FALSE;
@@ -3342,24 +3361,24 @@ PHP_FUNCTION(date_offset_get)
switch (dateobj->time->zone_type) {
case TIMELIB_ZONETYPE_ID:
offset = timelib_get_time_zone_info(dateobj->time->sse, dateobj->time->tz_info);
- RETVAL_INT(offset->offset);
+ RETVAL_LONG(offset->offset);
timelib_time_offset_dtor(offset);
break;
case TIMELIB_ZONETYPE_OFFSET:
- RETVAL_INT(dateobj->time->z * -60);
+ RETVAL_LONG(dateobj->time->z * -60);
break;
case TIMELIB_ZONETYPE_ABBR:
- RETVAL_INT((dateobj->time->z - (60 * dateobj->time->dst)) * -60);
+ RETVAL_LONG((dateobj->time->z - (60 * dateobj->time->dst)) * -60);
break;
}
return;
} else {
- RETURN_INT(0);
+ RETURN_LONG(0);
}
}
/* }}} */
-static void php_date_time_set(zval *object, php_int_t h, php_int_t i, php_int_t s, zval *return_value TSRMLS_DC) /* {{{ */
+static void php_date_time_set(zval *object, zend_long h, zend_long i, zend_long s, zval *return_value TSRMLS_DC) /* {{{ */
{
php_date_obj *dateobj;
@@ -3377,9 +3396,9 @@ static void php_date_time_set(zval *object, php_int_t h, php_int_t i, php_int_t
PHP_FUNCTION(date_time_set)
{
zval *object;
- php_int_t h, i, s = 0;
+ zend_long h, i, s = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oii|i", &object, date_ce_date, &h, &i, &s) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll|l", &object, date_ce_date, &h, &i, &s) == FAILURE) {
RETURN_FALSE;
}
@@ -3394,9 +3413,9 @@ PHP_FUNCTION(date_time_set)
PHP_METHOD(DateTimeImmutable, setTime)
{
zval *object, new_object;
- php_int_t h, i, s = 0;
+ zend_long h, i, s = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oii|i", &object, date_ce_immutable, &h, &i, &s) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll|l", &object, date_ce_immutable, &h, &i, &s) == FAILURE) {
RETURN_FALSE;
}
@@ -3407,7 +3426,7 @@ PHP_METHOD(DateTimeImmutable, setTime)
}
/* }}} */
-static void php_date_date_set(zval *object, php_int_t y, php_int_t m, php_int_t d, zval *return_value TSRMLS_DC) /* {{{ */
+static void php_date_date_set(zval *object, zend_long y, zend_long m, zend_long d, zval *return_value TSRMLS_DC) /* {{{ */
{
php_date_obj *dateobj;
@@ -3425,9 +3444,9 @@ static void php_date_date_set(zval *object, php_int_t y, php_int_t m, php_int_t
PHP_FUNCTION(date_date_set)
{
zval *object;
- php_int_t y, m, d;
+ zend_long y, m, d;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oiii", &object, date_ce_date, &y, &m, &d) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olll", &object, date_ce_date, &y, &m, &d) == FAILURE) {
RETURN_FALSE;
}
@@ -3442,9 +3461,9 @@ PHP_FUNCTION(date_date_set)
PHP_METHOD(DateTimeImmutable, setDate)
{
zval *object, new_object;
- php_int_t y, m, d;
+ zend_long y, m, d;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oiii", &object, date_ce_immutable, &y, &m, &d) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olll", &object, date_ce_immutable, &y, &m, &d) == FAILURE) {
RETURN_FALSE;
}
@@ -3455,7 +3474,7 @@ PHP_METHOD(DateTimeImmutable, setDate)
}
/* }}} */
-static void php_date_isodate_set(zval *object, php_int_t y, php_int_t w, php_int_t d, zval *return_value TSRMLS_DC) /* {{{ */
+static void php_date_isodate_set(zval *object, zend_long y, zend_long w, zend_long d, zval *return_value TSRMLS_DC) /* {{{ */
{
php_date_obj *dateobj;
@@ -3477,9 +3496,9 @@ static void php_date_isodate_set(zval *object, php_int_t y, php_int_t w, php_int
PHP_FUNCTION(date_isodate_set)
{
zval *object;
- php_int_t y, w, d = 1;
+ zend_long y, w, d = 1;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oii|i", &object, date_ce_date, &y, &w, &d) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll|l", &object, date_ce_date, &y, &w, &d) == FAILURE) {
RETURN_FALSE;
}
@@ -3494,9 +3513,9 @@ PHP_FUNCTION(date_isodate_set)
PHP_METHOD(DateTimeImmutable, setISODate)
{
zval *object, new_object;
- php_int_t y, w, d = 1;
+ zend_long y, w, d = 1;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oii|i", &object, date_ce_immutable, &y, &w, &d) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll|l", &object, date_ce_immutable, &y, &w, &d) == FAILURE) {
RETURN_FALSE;
}
@@ -3507,7 +3526,7 @@ PHP_METHOD(DateTimeImmutable, setISODate)
}
/* }}} */
-static void php_date_timestamp_set(zval *object, php_int_t timestamp, zval *return_value TSRMLS_DC) /* {{{ */
+static void php_date_timestamp_set(zval *object, zend_long timestamp, zval *return_value TSRMLS_DC) /* {{{ */
{
php_date_obj *dateobj;
@@ -3523,9 +3542,9 @@ static void php_date_timestamp_set(zval *object, php_int_t timestamp, zval *retu
PHP_FUNCTION(date_timestamp_set)
{
zval *object;
- php_int_t timestamp;
+ zend_long timestamp;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oi", &object, date_ce_date, &timestamp) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, date_ce_date, &timestamp) == FAILURE) {
RETURN_FALSE;
}
@@ -3540,9 +3559,9 @@ PHP_FUNCTION(date_timestamp_set)
PHP_METHOD(DateTimeImmutable, setTimestamp)
{
zval *object, new_object;
- php_int_t timestamp;
+ zend_long timestamp;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oi", &object, date_ce_immutable, &timestamp) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, date_ce_immutable, &timestamp) == FAILURE) {
RETURN_FALSE;
}
@@ -3560,7 +3579,7 @@ PHP_FUNCTION(date_timestamp_get)
{
zval *object;
php_date_obj *dateobj;
- php_int_t timestamp;
+ zend_long timestamp;
int error;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, date_ce_interface) == FAILURE) {
@@ -3574,7 +3593,7 @@ PHP_FUNCTION(date_timestamp_get)
if (error) {
RETURN_FALSE;
} else {
- RETVAL_INT(timestamp);
+ RETVAL_LONG(timestamp);
}
}
/* }}} */
@@ -3587,9 +3606,9 @@ PHP_FUNCTION(date_diff)
zval *object1, *object2;
php_date_obj *dateobj1, *dateobj2;
php_interval_obj *interval;
- php_int_t absolute = 0;
+ zend_long absolute = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO|i", &object1, date_ce_interface, &object2, date_ce_interface, &absolute) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO|l", &object1, date_ce_interface, &object2, date_ce_interface, &absolute) == FAILURE) {
RETURN_FALSE;
}
dateobj1 = Z_PHPDATE_P(object1);
@@ -3633,7 +3652,7 @@ static int timezone_initialize(php_timezone_obj *tzobj, /*const*/ char *tz TSRML
PHP_FUNCTION(timezone_open)
{
char *tz;
- int tz_len;
+ size_t tz_len;
php_timezone_obj *tzobj;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &tz, &tz_len) == FAILURE) {
@@ -3652,7 +3671,7 @@ PHP_FUNCTION(timezone_open)
PHP_METHOD(DateTimeZone, __construct)
{
char *tz;
- int tz_len;
+ size_t tz_len;
php_timezone_obj *tzobj;
zend_error_handling error_handling;
@@ -3674,7 +3693,7 @@ static int php_date_timezone_initialize_from_hash(zval **return_value, php_timez
if ((z_timezone_type = zend_hash_str_find(myht, "timezone_type", sizeof("timezone_type")-1)) != NULL) {
if ((z_timezone = zend_hash_str_find(myht, "timezone", sizeof("timezone")-1)) != NULL) {
- convert_to_int(z_timezone_type);
+ convert_to_long(z_timezone_type);
if (SUCCESS == timezone_initialize(*tzobj, Z_STRVAL_P(z_timezone) TSRMLS_CC)) {
return SUCCESS;
}
@@ -3738,7 +3757,7 @@ PHP_FUNCTION(timezone_name_get)
RETURN_STRING(tzobj->tzi.tz->name);
break;
case TIMELIB_ZONETYPE_OFFSET: {
- zend_string *tmpstr = STR_ALLOC(sizeof("UTC+05:00")-1, 0);
+ zend_string *tmpstr = zend_string_alloc(sizeof("UTC+05:00")-1, 0);
timelib_sll utc_offset = tzobj->tzi.utc_offset;
tmpstr->len = snprintf(tmpstr->val, sizeof("+05:00"), "%c%02d:%02d",
@@ -3763,11 +3782,11 @@ PHP_FUNCTION(timezone_name_from_abbr)
{
char *abbr;
char *tzid;
- int abbr_len;
- php_int_t gmtoffset = -1;
- php_int_t isdst = -1;
+ size_t abbr_len;
+ zend_long gmtoffset = -1;
+ zend_long isdst = -1;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ii", &abbr, &abbr_len, &gmtoffset, &isdst) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &abbr, &abbr_len, &gmtoffset, &isdst) == FAILURE) {
RETURN_FALSE;
}
tzid = timelib_timezone_id_from_abbr(abbr, gmtoffset, isdst);
@@ -3780,7 +3799,7 @@ PHP_FUNCTION(timezone_name_from_abbr)
}
/* }}} */
-/* {{{ proto long timezone_offset_get(DateTimeZone object, DateTime object)
+/* {{{ proto long timezone_offset_get(DateTimeZone object, DateTimeInterface datetime)
Returns the timezone offset.
*/
PHP_FUNCTION(timezone_offset_get)
@@ -3790,25 +3809,25 @@ PHP_FUNCTION(timezone_offset_get)
php_date_obj *dateobj;
timelib_time_offset *offset;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, date_ce_timezone, &dateobject, date_ce_date) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, date_ce_timezone, &dateobject, date_ce_interface) == FAILURE) {
RETURN_FALSE;
}
tzobj = Z_PHPTIMEZONE_P(object);
DATE_CHECK_INITIALIZED(tzobj->initialized, DateTimeZone);
dateobj = Z_PHPDATE_P(dateobject);
- DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
+ DATE_CHECK_INITIALIZED(dateobj->time, DateTimeInterface);
switch (tzobj->type) {
case TIMELIB_ZONETYPE_ID:
offset = timelib_get_time_zone_info(dateobj->time->sse, tzobj->tzi.tz);
- RETVAL_INT(offset->offset);
+ RETVAL_LONG(offset->offset);
timelib_time_offset_dtor(offset);
break;
case TIMELIB_ZONETYPE_OFFSET:
- RETURN_INT(tzobj->tzi.utc_offset * -60);
+ RETURN_LONG(tzobj->tzi.utc_offset * -60);
break;
case TIMELIB_ZONETYPE_ABBR:
- RETURN_INT((tzobj->tzi.z.utc_offset - (tzobj->tzi.z.dst*60)) * -60);
+ RETURN_LONG((tzobj->tzi.z.utc_offset - (tzobj->tzi.z.dst*60)) * -60);
break;
}
}
@@ -3822,9 +3841,9 @@ PHP_FUNCTION(timezone_transitions_get)
zval *object, element;
php_timezone_obj *tzobj;
unsigned int i, begin = 0, found;
- php_int_t timestamp_begin = PHP_INT_MIN, timestamp_end = PHP_INT_MAX;
+ zend_long timestamp_begin = ZEND_LONG_MIN, timestamp_end = ZEND_LONG_MAX;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|ii", &object, date_ce_timezone, &timestamp_begin, &timestamp_end) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|ll", &object, date_ce_timezone, &timestamp_begin, &timestamp_end) == FAILURE) {
RETURN_FALSE;
}
tzobj = Z_PHPTIMEZONE_P(object);
@@ -3835,18 +3854,18 @@ PHP_FUNCTION(timezone_transitions_get)
#define add_nominal() \
array_init(&element); \
- add_assoc_int(&element, "ts", timestamp_begin); \
+ add_assoc_long(&element, "ts", timestamp_begin); \
add_assoc_str(&element, "time", php_format_date(DATE_FORMAT_ISO8601, 13, timestamp_begin, 0 TSRMLS_CC)); \
- add_assoc_int(&element, "offset", tzobj->tzi.tz->type[0].offset); \
+ add_assoc_long(&element, "offset", tzobj->tzi.tz->type[0].offset); \
add_assoc_bool(&element, "isdst", tzobj->tzi.tz->type[0].isdst); \
add_assoc_string(&element, "abbr", &tzobj->tzi.tz->timezone_abbr[tzobj->tzi.tz->type[0].abbr_idx]); \
add_next_index_zval(return_value, &element);
#define add(i,ts) \
array_init(&element); \
- add_assoc_int(&element, "ts", ts); \
+ add_assoc_long(&element, "ts", ts); \
add_assoc_str(&element, "time", php_format_date(DATE_FORMAT_ISO8601, 13, ts, 0 TSRMLS_CC)); \
- add_assoc_int(&element, "offset", tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].offset); \
+ add_assoc_long(&element, "offset", tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].offset); \
add_assoc_bool(&element, "isdst", tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].isdst); \
add_assoc_string(&element, "abbr", &tzobj->tzi.tz->timezone_abbr[tzobj->tzi.tz->type[tzobj->tzi.tz->trans_idx[i]].abbr_idx]); \
add_next_index_zval(return_value, &element);
@@ -3855,7 +3874,7 @@ PHP_FUNCTION(timezone_transitions_get)
array_init(return_value);
- if (timestamp_begin == PHP_INT_MIN) {
+ if (timestamp_begin == ZEND_LONG_MIN) {
add_nominal();
begin = 0;
found = 1;
@@ -4005,7 +4024,7 @@ zval *date_interval_read_property(zval *object, zval *member, int type, void **c
retval = rv;
if (value != -99999) {
- ZVAL_INT(retval, value);
+ ZVAL_LONG(retval, value);
} else {
ZVAL_FALSE(retval);
}
@@ -4044,7 +4063,7 @@ void date_interval_write_property(zval *object, zval *member, zval *value, void
#define SET_VALUE_FROM_STRUCT(n,m) \
if (strcmp(Z_STRVAL_P(member), m) == 0) { \
- obj->diff->n = zval_get_int(value); \
+ obj->diff->n = zval_get_long(value); \
break; \
}
@@ -4073,7 +4092,7 @@ void date_interval_write_property(zval *object, zval *member, zval *value, void
PHP_METHOD(DateInterval, __construct)
{
char *interval_string = NULL;
- int interval_string_length;
+ size_t interval_string_length;
php_interval_obj *diobj;
timelib_rel_time *reltime;
zend_error_handling error_handling;
@@ -4101,7 +4120,7 @@ static int php_date_interval_initialize_from_hash(zval **return_value, php_inter
do { \
zval *z_arg = zend_hash_str_find(myht, element, sizeof(element) - 1); \
if (z_arg) { \
- (*intobj)->diff->member = (itype)zval_get_int(z_arg); \
+ (*intobj)->diff->member = (itype)zval_get_long(z_arg); \
} else { \
(*intobj)->diff->member = (itype)def; \
} \
@@ -4112,8 +4131,8 @@ static int php_date_interval_initialize_from_hash(zval **return_value, php_inter
zval *z_arg = zend_hash_str_find(myht, element, sizeof(element) - 1); \
if (z_arg) { \
zend_string *str = zval_get_string(z_arg); \
- ZEND_ATOI((*intobj)->diff->member, str->val); \
- STR_RELEASE(str); \
+ DATE_A64I((*intobj)->diff->member, str->val); \
+ zend_string_release(str); \
} else { \
(*intobj)->diff->member = -1LL; \
} \
@@ -4181,7 +4200,7 @@ PHP_METHOD(DateInterval, __wakeup)
PHP_FUNCTION(date_interval_create_from_date_string)
{
char *time_str = NULL;
- int time_str_len = 0;
+ size_t time_str_len = 0;
timelib_time *time;
timelib_error_container *err = NULL;
php_interval_obj *diobj;
@@ -4230,8 +4249,8 @@ static zend_string *date_interval_format(char *format, int format_len, timelib_r
case 'I': length = slprintf(buffer, 32, "%02d", (int) t->i); break;
case 'i': length = slprintf(buffer, 32, "%d", (int) t->i); break;
- case 'S': length = slprintf(buffer, 32, "%02" ZEND_INT_FMT_SPEC, (php_int_t) t->s); break;
- case 's': length = slprintf(buffer, 32, ZEND_INT_FMT, (php_int_t) t->s); break;
+ case 'S': length = slprintf(buffer, 32, "%02" ZEND_LONG_FMT_SPEC, (zend_long) t->s); break;
+ case 's': length = slprintf(buffer, 32, ZEND_LONG_FMT, (zend_long) t->s); break;
case 'a': {
if ((int) t->days != -99999) {
@@ -4271,7 +4290,7 @@ PHP_FUNCTION(date_interval_format)
zval *object;
php_interval_obj *diobj;
char *format;
- int format_len;
+ size_t format_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, date_ce_interval, &format, &format_len) == FAILURE) {
RETURN_FALSE;
@@ -4283,7 +4302,7 @@ PHP_FUNCTION(date_interval_format)
}
/* }}} */
-static int date_period_initialize(timelib_time **st, timelib_time **et, timelib_rel_time **d, php_int_t *recurrences, /*const*/ char *format, int format_length TSRMLS_DC) /* {{{ */
+static int date_period_initialize(timelib_time **st, timelib_time **et, timelib_rel_time **d, zend_long *recurrences, /*const*/ char *format, int format_length TSRMLS_DC) /* {{{ */
{
timelib_time *b = NULL, *e = NULL;
timelib_rel_time *p = NULL;
@@ -4316,16 +4335,16 @@ PHP_METHOD(DatePeriod, __construct)
php_date_obj *dateobj;
php_interval_obj *intobj;
zval *start, *end = NULL, *interval;
- php_int_t recurrences = 0, options = 0;
+ zend_long recurrences = 0, options = 0;
char *isostr = NULL;
- int isostr_len = 0;
+ size_t isostr_len = 0;
timelib_time *clone;
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "OOi|i", &start, date_ce_interface, &interval, date_ce_interval, &recurrences, &options) == FAILURE) {
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "OOO|i", &start, date_ce_interface, &interval, date_ce_interval, &end, date_ce_interface, &options) == FAILURE) {
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s|i", &isostr, &isostr_len, &options) == FAILURE) {
+ if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "OOl|l", &start, date_ce_interface, &interval, date_ce_interval, &recurrences, &options) == FAILURE) {
+ if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "OOO|l", &start, date_ce_interface, &interval, date_ce_interval, &end, date_ce_interface, &options) == FAILURE) {
+ if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &isostr, &isostr_len, &options) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "This constructor accepts either (DateTimeInterface, DateInterval, int) OR (DateTimeInterface, DateInterval, DateTime) OR (string) as arguments.");
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
@@ -4395,7 +4414,7 @@ PHP_METHOD(DatePeriod, __construct)
}
/* }}} */
-static int check_id_allowed(char *id, php_int_t what) /* {{{ */
+static int check_id_allowed(char *id, zend_long what) /* {{{ */
{
if (what & PHP_DATE_TIMEZONE_GROUP_AFRICA && strncasecmp(id, "Africa/", 7) == 0) return 1;
if (what & PHP_DATE_TIMEZONE_GROUP_AMERICA && strncasecmp(id, "America/", 8) == 0) return 1;
@@ -4419,11 +4438,11 @@ PHP_FUNCTION(timezone_identifiers_list)
const timelib_tzdb *tzdb;
const timelib_tzdb_index_entry *table;
int i, item_count;
- php_int_t what = PHP_DATE_TIMEZONE_GROUP_ALL;
+ zend_long what = PHP_DATE_TIMEZONE_GROUP_ALL;
char *option = NULL;
- int option_len = 0;
+ size_t option_len = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|is", &what, &option, &option_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ls", &what, &option, &option_len) == FAILURE) {
RETURN_FALSE;
}
@@ -4477,12 +4496,12 @@ PHP_FUNCTION(timezone_abbreviations_list)
do {
array_init(&element);
- add_assoc_bool(&element, "dst", entry->type);
- add_assoc_int(&element, "offset", entry->gmtoffset);
+ add_assoc_bool_ex(&element, "dst", sizeof("dst") -1, entry->type);
+ add_assoc_long_ex(&element, "offset", sizeof("offset") - 1, entry->gmtoffset);
if (entry->full_tz_name) {
- add_assoc_string(&element, "timezone_id", entry->full_tz_name);
+ add_assoc_string_ex(&element, "timezone_id", sizeof("timezone_id") - 1, entry->full_tz_name);
} else {
- add_assoc_null(&element, "timezone_id");
+ add_assoc_null_ex(&element, "timezone_id", sizeof("timezone_id") - 1);
}
abbr_array_p = zend_hash_str_find(HASH_OF(return_value), entry->name, strlen(entry->name));
@@ -4503,7 +4522,7 @@ PHP_FUNCTION(timezone_abbreviations_list)
PHP_FUNCTION(date_default_timezone_set)
{
char *zone;
- int zone_len;
+ size_t zone_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &zone, &zone_len) == FAILURE) {
RETURN_FALSE;
@@ -4540,13 +4559,13 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_su
double latitude = 0.0, longitude = 0.0, zenith = 0.0, gmt_offset = 0, altitude;
double h_rise, h_set, N;
timelib_sll rise, set, transit;
- php_int_t time, retformat = 0;
+ zend_long time, retformat = 0;
int rs;
timelib_time *t;
timelib_tzinfo *tzi;
zend_string *retstr;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i|idddd", &time, &retformat, &latitude, &longitude, &zenith, &gmt_offset) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ldddd", &time, &retformat, &latitude, &longitude, &zenith, &gmt_offset) == FAILURE) {
RETURN_FALSE;
}
@@ -4599,7 +4618,7 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_su
}
if (retformat == SUNFUNCS_RET_TIMESTAMP) {
- RETURN_INT(calc_sunset ? set : rise);
+ RETURN_LONG(calc_sunset ? set : rise);
}
N = (calc_sunset ? h_set : h_rise) + gmt_offset;
@@ -4639,7 +4658,7 @@ PHP_FUNCTION(date_sunset)
Returns an array with information about sun set/rise and twilight begin/end */
PHP_FUNCTION(date_sun_info)
{
- php_int_t time;
+ zend_long time;
double latitude, longitude;
timelib_time *t, *t2;
timelib_tzinfo *tzi;
@@ -4648,7 +4667,7 @@ PHP_FUNCTION(date_sun_info)
int dummy;
double ddummy;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "idd", &time, &latitude, &longitude) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ldd", &time, &latitude, &longitude) == FAILURE) {
RETURN_FALSE;
}
/* Initialize time struct */
@@ -4675,12 +4694,12 @@ PHP_FUNCTION(date_sun_info)
break;
default:
t2->sse = rise;
- add_assoc_int(return_value, "sunrise", timelib_date_to_int(t2, &dummy));
+ add_assoc_long(return_value, "sunrise", timelib_date_to_int(t2, &dummy));
t2->sse = set;
- add_assoc_int(return_value, "sunset", timelib_date_to_int(t2, &dummy));
+ add_assoc_long(return_value, "sunset", timelib_date_to_int(t2, &dummy));
}
t2->sse = transit;
- add_assoc_int(return_value, "transit", timelib_date_to_int(t2, &dummy));
+ add_assoc_long(return_value, "transit", timelib_date_to_int(t2, &dummy));
/* Get civil twilight */
rs = timelib_astro_rise_set_altitude(t, longitude, latitude, -6.0, 0, &ddummy, &ddummy, &rise, &set, &transit);
@@ -4695,9 +4714,9 @@ PHP_FUNCTION(date_sun_info)
break;
default:
t2->sse = rise;
- add_assoc_int(return_value, "civil_twilight_begin", timelib_date_to_int(t2, &dummy));
+ add_assoc_long(return_value, "civil_twilight_begin", timelib_date_to_int(t2, &dummy));
t2->sse = set;
- add_assoc_int(return_value, "civil_twilight_end", timelib_date_to_int(t2, &dummy));
+ add_assoc_long(return_value, "civil_twilight_end", timelib_date_to_int(t2, &dummy));
}
/* Get nautical twilight */
@@ -4713,9 +4732,9 @@ PHP_FUNCTION(date_sun_info)
break;
default:
t2->sse = rise;
- add_assoc_int(return_value, "nautical_twilight_begin", timelib_date_to_int(t2, &dummy));
+ add_assoc_long(return_value, "nautical_twilight_begin", timelib_date_to_int(t2, &dummy));
t2->sse = set;
- add_assoc_int(return_value, "nautical_twilight_end", timelib_date_to_int(t2, &dummy));
+ add_assoc_long(return_value, "nautical_twilight_end", timelib_date_to_int(t2, &dummy));
}
/* Get astronomical twilight */
@@ -4731,9 +4750,9 @@ PHP_FUNCTION(date_sun_info)
break;
default:
t2->sse = rise;
- add_assoc_int(return_value, "astronomical_twilight_begin", timelib_date_to_int(t2, &dummy));
+ add_assoc_long(return_value, "astronomical_twilight_begin", timelib_date_to_int(t2, &dummy));
t2->sse = set;
- add_assoc_int(return_value, "astronomical_twilight_end", timelib_date_to_int(t2, &dummy));
+ add_assoc_long(return_value, "astronomical_twilight_end", timelib_date_to_int(t2, &dummy));
}
timelib_time_dtor(t);
timelib_time_dtor(t2);
@@ -4803,7 +4822,7 @@ static HashTable *date_object_get_properties_period(zval *object TSRMLS_DC) /* {
zend_hash_str_update(props, "interval", sizeof("interval")-1, &zv);
/* converted to larger type (int->long); must check when unserializing */
- ZVAL_INT(&zv, (long) period_obj->recurrences);
+ ZVAL_LONG(&zv, (zend_long) period_obj->recurrences);
zend_hash_str_update(props, "recurrences", sizeof("recurrences")-1, &zv);
ZVAL_BOOL(&zv, period_obj->include_start_date);
@@ -4873,8 +4892,8 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
ht_entry = zend_hash_str_find(myht, "recurrences", sizeof("recurrences")-1);
if (ht_entry &&
- Z_TYPE_P(ht_entry) == IS_INT && Z_IVAL_P(ht_entry) >= 0 && Z_IVAL_P(ht_entry) <= INT_MAX) {
- period_obj->recurrences = Z_IVAL_P(ht_entry);
+ Z_TYPE_P(ht_entry) == IS_LONG && Z_LVAL_P(ht_entry) >= 0 && Z_LVAL_P(ht_entry) <= INT_MAX) {
+ period_obj->recurrences = Z_LVAL_P(ht_entry);
} else {
return 0;
}