]> granicus.if.org Git - php/commitdiff
MFH: Add Datetime::createFromTimestamp to allow setting of a unix timestamp without...
authorScott MacVicar <scottmac@php.net>
Fri, 14 Dec 2007 14:28:36 +0000 (14:28 +0000)
committerScott MacVicar <scottmac@php.net>
Fri, 14 Dec 2007 14:28:36 +0000 (14:28 +0000)
NEWS
ext/date/php_date.c
ext/date/php_date.h

diff --git a/NEWS b/NEWS
index a513f4709b2381edca155cac66b627509c0c3edc..0d51ed9f6dc64685d4804bd1e8a98a64382b47cf 100644 (file)
--- 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)
 
index 57205e44b05016a6b833c737f85a517b5875df32..5b7d582c68e478e78749bd7668602f03f1d77c20 100644 (file)
@@ -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, &timestamp) == 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;
index beadd141280c69809576643e5417e74f0008089e..d3b27a4db27938386041a7edf11851507173539b 100644 (file)
@@ -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);