From: Derick Rethans Date: Mon, 28 Jan 2008 20:30:51 +0000 (+0000) Subject: - MFH: Added date_timestamp_get() / DateTime::getTimestamp() to retrieve the X-Git-Tag: RELEASE_1_3_1~267 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ffbe501ad2d77b5f30be02531092dfcfab12a76e;p=php - MFH: Added date_timestamp_get() / DateTime::getTimestamp() to retrieve the Unix timestamp belonging to a date object. --- diff --git a/NEWS b/NEWS index 1dc1538fc9..a529634ac1 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,8 @@ PHP NEWS timezone_identifiers_list() / DateTimezone::listIdentifiers(). * date_timestamp_set() / DateTime::setTimestamp() to set a Unix timestamp without invoking the date parser. (Scott) + * date_timestamp_get() / DateTime::getTimestamp() to retrieve the Unix + timestamp belonging to a date object. - Added ability to store associative infor with objects in SplObjectStorage. (Marcus) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index fa025d6f66..5f4eb567fa 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -182,6 +182,7 @@ const zend_function_entry date_functions[] = { PHP_FE(date_date_set, NULL) PHP_FE(date_isodate_set, NULL) PHP_FE(date_timestamp_set, NULL) + PHP_FE(date_timestamp_get, NULL) PHP_FE(timezone_open, NULL) PHP_FE(timezone_name_get, NULL) @@ -215,6 +216,7 @@ const zend_function_entry date_funcs_date[] = { PHP_ME_MAPPING(setDate, date_date_set, NULL, 0) PHP_ME_MAPPING(setISODate, date_isodate_set, NULL, 0) PHP_ME_MAPPING(setTimestamp, date_timestamp_set, NULL, 0) + PHP_ME_MAPPING(getTimestamp, date_timestamp_get, NULL, 0) {NULL, NULL, NULL} }; @@ -2267,6 +2269,32 @@ PHP_FUNCTION(date_timestamp_set) } /* }}} */ +/* {{{ proto long date_timestamp_get(DateTime object) + Gets the Unix timestamp. +*/ +PHP_FUNCTION(date_timestamp_get) +{ + zval *object; + php_date_obj *dateobj; + long timestamp; + int error; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, date_ce_date) == FAILURE) { + RETURN_FALSE; + } + dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC); + DATE_CHECK_INITIALIZED(dateobj->time, DateTime); + timelib_update_ts(dateobj->time, NULL); + + timestamp = timelib_date_to_int(dateobj->time, &error); + if (error) { + RETURN_FALSE; + } else { + RETVAL_LONG(timestamp); + } +} +/* }}} */ + 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 ce2a44e90f..5804f2a2c4 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -63,6 +63,7 @@ PHP_FUNCTION(date_time_set); PHP_FUNCTION(date_date_set); PHP_FUNCTION(date_isodate_set); PHP_FUNCTION(date_timestamp_set); +PHP_FUNCTION(date_timestamp_get); PHP_METHOD(DateTimeZone, __construct); PHP_FUNCTION(timezone_open);