summaryrefslogtreecommitdiff
path: root/ext/date/php_date.c
diff options
context:
space:
mode:
authorScott MacVicar <scottmac@php.net>2007-12-14 14:28:36 +0000
committerScott MacVicar <scottmac@php.net>2007-12-14 14:28:36 +0000
commit6f04c5169e773f7a73dc224c0cbab427c44a20aa (patch)
tree980c10a3c9af006bfec96771331eabddfcaf090e /ext/date/php_date.c
parentf817a1ce6a18a7751f69d7d52781b54a399080e5 (diff)
downloadphp-git-6f04c5169e773f7a73dc224c0cbab427c44a20aa.tar.gz
MFH: Add Datetime::createFromTimestamp to allow setting of a unix timestamp without invoking the date parser.
Diffstat (limited to 'ext/date/php_date.c')
-rw-r--r--ext/date/php_date.c21
1 files changed, 21 insertions, 0 deletions
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, &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;