Browse Source

- MFH: Added date_timestamp_get() / DateTime::getTimestamp() to retrieve the

Unix timestamp belonging to a date object.
PECL
Derick Rethans 19 years ago
parent
commit
ffbe501ad2
  1. 2
      NEWS
  2. 28
      ext/date/php_date.c
  3. 1
      ext/date/php_date.h

2
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)

28
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;

1
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);

Loading…
Cancel
Save