From: Scott MacVicar Date: Fri, 14 Dec 2007 14:28:36 +0000 (+0000) Subject: MFH: Add Datetime::createFromTimestamp to allow setting of a unix timestamp without... X-Git-Tag: RELEASE_1_3_1~506 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f04c5169e773f7a73dc224c0cbab427c44a20aa;p=php MFH: Add Datetime::createFromTimestamp to allow setting of a unix timestamp without invoking the date parser. --- diff --git a/NEWS b/NEWS index a513f4709b..0d51ed9f6d 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,8 @@ PHP NEWS (Etienne Kneuss) - Added "compact" handler for Zend MM storage. (Dmitry) - Added "+" and "*" specifiers to zend_parse_parameters(). (Andrei) +- Added DateTime::createFromTimestamp() to set a unix timestamp without + invoking the date parser. (Scott) - Upgraded PCRE to version 7.4 (Nuno) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 57205e44b0..5b7d582c68 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -178,6 +178,7 @@ const zend_function_entry date_functions[] = { PHP_FE(date_time_set, NULL) PHP_FE(date_date_set, NULL) PHP_FE(date_isodate_set, NULL) + PHP_FE(date_timestamp_set, NULL) PHP_FE(timezone_open, NULL) PHP_FE(timezone_name_get, NULL) @@ -208,6 +209,7 @@ const zend_function_entry date_funcs_date[] = { PHP_ME_MAPPING(setTime, date_time_set, NULL, 0) PHP_ME_MAPPING(setDate, date_date_set, NULL, 0) PHP_ME_MAPPING(setISODate, date_isodate_set, NULL, 0) + PHP_ME_MAPPING(createFromTimestamp, date_timestamp_set, NULL, 0) {NULL, NULL, NULL} }; @@ -2014,6 +2016,25 @@ PHP_FUNCTION(date_isodate_set) } /* }}} */ +/* {{{ proto void date_timestamp_set(DateTime object, long unixTimestamp) + Sets the date and time based on an Unix timestamp. +*/ +PHP_FUNCTION(date_timestamp_set) +{ + zval *object; + php_date_obj *dateobj; + long timestamp; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, date_ce_date, ×tamp) == FAILURE) { + RETURN_FALSE; + } + dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC); + DATE_CHECK_INITIALIZED(dateobj->time, DateTime); + timelib_unixtime2gmt(dateobj->time, (timelib_sll)timestamp); + timelib_update_ts(dateobj->time, NULL); +} +/* }}} */ + static int timezone_initialize(timelib_tzinfo **tzi, /*const*/ char *tz TSRMLS_DC) { char *tzid; diff --git a/ext/date/php_date.h b/ext/date/php_date.h index beadd14128..d3b27a4db2 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -59,6 +59,7 @@ PHP_FUNCTION(date_offset_get); PHP_FUNCTION(date_time_set); PHP_FUNCTION(date_date_set); PHP_FUNCTION(date_isodate_set); +PHP_FUNCTION(date_timestamp_set); PHP_METHOD(DateTimeZone, __construct); PHP_FUNCTION(timezone_open);