Skip to content

Commit 4a11068

Browse files
committed
Fix ext/date
1 parent 9ca3626 commit 4a11068

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

ext/date/php_date.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,18 @@ static const char *php_date_short_day_name(timelib_sll y, timelib_sll m, timelib
672672
}
673673
/* }}} */
674674

675+
static zend_long date_date_to_zlong(timelib_time *d, int *error)
676+
{
677+
#if SIZEOF_ZEND_LONG >= SIZEOF_LONG_LONG
678+
if (error) {
679+
*error = 0;
680+
}
681+
return (zend_long) d->sse;
682+
#else
683+
return timelib_date_to_int(d, error);
684+
#endif
685+
}
686+
675687
/* {{{ date_format - (gm)date helper */
676688
static zend_string *date_format(const char *format, size_t format_len, const timelib_time *t, bool localtime)
677689
{
@@ -874,7 +886,7 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, bool localtime)
874886
}
875887
/* }}} */
876888

877-
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, bool localtime) /* {{{ */
889+
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, zend_long ts, bool localtime) /* {{{ */
878890
{
879891
timelib_time *t;
880892
timelib_tzinfo *tzi;
@@ -1125,7 +1137,7 @@ PHP_FUNCTION(strtotime)
11251137

11261138
timelib_fill_holes(t, now, TIMELIB_NO_CLONE);
11271139
timelib_update_ts(t, tzi);
1128-
ts = timelib_date_to_int(t, &epoch_does_not_fit_in_zend_long);
1140+
ts = date_date_to_zlong(t, &epoch_does_not_fit_in_zend_long);
11291141

11301142
timelib_time_dtor(now);
11311143
timelib_time_dtor(t);
@@ -1208,8 +1220,7 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, bool gmt)
12081220
}
12091221

12101222
/* Clean up and return */
1211-
ts = timelib_date_to_int(now, &epoch_does_not_fit_in_zend_long);
1212-
1223+
ts = date_date_to_zlong(now, &epoch_does_not_fit_in_zend_long);
12131224
if (epoch_does_not_fit_in_zend_long) {
12141225
timelib_time_dtor(now);
12151226
php_error_docref(NULL, E_WARNING, "Epoch doesn't fit in a PHP integer");
@@ -3915,7 +3926,7 @@ PHP_FUNCTION(date_timestamp_get)
39153926
timelib_update_ts(dateobj->time, NULL);
39163927
}
39173928

3918-
timestamp = timelib_date_to_int(dateobj->time, &epoch_does_not_fit_in_zend_long);
3929+
timestamp = date_date_to_zlong(dateobj->time, &epoch_does_not_fit_in_zend_long);
39193930

39203931
if (epoch_does_not_fit_in_zend_long) {
39213932
zend_throw_error(date_ce_date_range_error, "Epoch doesn't fit in a PHP integer");

ext/date/php_date.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ PHPAPI int php_idate(char format, time_t ts, bool localtime);
139139
#define _php_strftime php_strftime
140140

141141
PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, bool gm);
142-
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, bool localtime);
142+
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, zend_long ts, bool localtime);
143143
PHPAPI zend_string *php_format_date_obj(const char *format, size_t format_len, const php_date_obj *date_obj);
144144

145145
/* Mechanism to set new TZ database */

0 commit comments

Comments
 (0)