]> granicus.if.org Git - php/commitdiff
- MFH: Added date_timestamp_get() / DateTime::getTimestamp() to retrieve the
authorDerick Rethans <derick@php.net>
Mon, 28 Jan 2008 20:30:51 +0000 (20:30 +0000)
committerDerick Rethans <derick@php.net>
Mon, 28 Jan 2008 20:30:51 +0000 (20:30 +0000)
  Unix timestamp belonging to a date object.

NEWS
ext/date/php_date.c
ext/date/php_date.h

diff --git a/NEWS b/NEWS
index 1dc1538fc98317a81d7c0a56190097c1db47c4fe..a529634ac1facf739b026c47a538ddf8fcc112c5 100644 (file)
--- 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)
index fa025d6f667fd8c44bd9cb1de0a0d088576089b7..5f4eb567fa6d7a0c7dbce5db878ffaaaa3d6b8b0 100644 (file)
@@ -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;
index ce2a44e90fd0083ede7fb61cb70629861b5c205b..5804f2a2c4b03da4c0d767ffc8a663394bdd8282 100644 (file)
@@ -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);