diff options
author | Derick Rethans <derick@php.net> | 2005-07-03 20:45:08 +0000 |
---|---|---|
committer | Derick Rethans <derick@php.net> | 2005-07-03 20:45:08 +0000 |
commit | 8aa3554d1937a501841635bf636768fd6e07b08f (patch) | |
tree | 85ce4aacc8441289aa6406d1cd5cfddcedb00933 /ext/date/php_date.c | |
parent | 0ef991e5ae409ecddedc6cfbb8231236ef84b936 (diff) | |
download | php-git-8aa3554d1937a501841635bf636768fd6e07b08f.tar.gz |
- Reimplemented time(), getdate() and localtime() functions with new datetime
library.
Diffstat (limited to 'ext/date/php_date.c')
-rw-r--r-- | ext/date/php_date.c | 97 |
1 files changed, 96 insertions, 1 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c index f91ad7cdec..798f77e321 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -29,14 +29,22 @@ #include <time.h> function_entry date_functions[] = { + PHP_FE(strtotime, NULL) PHP_FE(date, NULL) PHP_FE(gmdate, NULL) PHP_FE(mktime, NULL) PHP_FE(checkdate, NULL) PHP_FE(gmstrftime, NULL) + +#if HAVE_STRFTIME PHP_FE(strftime, NULL) PHP_FE(gmmktime, NULL) - PHP_FE(strtotime, NULL) +#endif + + PHP_FE(time, NULL) + PHP_FE(localtime, NULL) + PHP_FE(getdate, NULL) + PHP_FE(date_timezone_set, NULL) PHP_FE(date_timezone_get, NULL) {NULL, NULL, NULL} @@ -641,6 +649,93 @@ PHP_FUNCTION(gmstrftime) /* }}} */ #endif +/* {{{ proto int time(void) + Return current UNIX timestamp */ +PHP_FUNCTION(time) +{ + RETURN_LONG((long)time(NULL)); +} +/* }}} */ + +/* {{{ proto array localtime([int timestamp [, bool associative_array]]) + Returns the results of the C system call localtime as an associative array if the associative_array argument is set to 1 other wise it is a regular array */ +PHP_FUNCTION(localtime) +{ + long timestamp = (long)time(NULL); + int associative = 0; + timelib_tzinfo *tzi; + timelib_time *ts; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", ×tamp, &associative) == FAILURE) { + RETURN_FALSE; + } + + tzi = get_timezone_info(TSRMLS_C); + ts = timelib_time_ctor(); + timelib_unixtime2local(ts, (timelib_sll) timestamp, tzi); + + array_init(return_value); + + if (associative) { + add_assoc_long(return_value, "tm_sec", ts->s); + add_assoc_long(return_value, "tm_min", ts->i); + add_assoc_long(return_value, "tm_hour", ts->h); + add_assoc_long(return_value, "tm_mday", ts->d); + add_assoc_long(return_value, "tm_mon", ts->m - 1); + add_assoc_long(return_value, "tm_year", ts->y - 1900); + add_assoc_long(return_value, "tm_wday", timelib_day_of_week(ts->y, ts->m, ts->d)); + add_assoc_long(return_value, "tm_yday", timelib_day_of_year(ts->y, ts->m, ts->d)); + add_assoc_long(return_value, "tm_isdst", ts->dst); + } else { + add_next_index_long(return_value, ts->s); + add_next_index_long(return_value, ts->i); + add_next_index_long(return_value, ts->h); + add_next_index_long(return_value, ts->d); + add_next_index_long(return_value, ts->m - 1); + add_next_index_long(return_value, ts->y- 1900); + add_next_index_long(return_value, timelib_day_of_week(ts->y, ts->m, ts->d)); + add_next_index_long(return_value, timelib_day_of_year(ts->y, ts->m, ts->d)); + add_next_index_long(return_value, ts->dst); + } + + timelib_time_dtor(ts); +} +/* }}} */ + +/* {{{ proto array getdate([int timestamp]) + Get date/time information */ +PHP_FUNCTION(getdate) +{ + long timestamp = (long)time(NULL); + timelib_tzinfo *tzi; + timelib_time *ts; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", ×tamp) == FAILURE) { + RETURN_FALSE; + } + + tzi = get_timezone_info(TSRMLS_C); + ts = timelib_time_ctor(); + timelib_unixtime2local(ts, (timelib_sll) timestamp, tzi); + + array_init(return_value); + + add_assoc_long(return_value, "seconds", ts->s); + add_assoc_long(return_value, "minutes", ts->i); + add_assoc_long(return_value, "hours", ts->h); + add_assoc_long(return_value, "mday", ts->d); + add_assoc_long(return_value, "wday", timelib_day_of_week(ts->y, ts->m, ts->d)); + add_assoc_long(return_value, "mon", ts->m); + add_assoc_long(return_value, "year", ts->y); + add_assoc_long(return_value, "yday", timelib_day_of_year(ts->y, ts->m, ts->d)); + add_assoc_string(return_value, "weekday", day_full_names[timelib_day_of_week(ts->y, ts->m, ts->d)], 1); + add_assoc_string(return_value, "month", mon_full_names[ts->m - 1], 1); + add_index_long(return_value, 0, timestamp); + + timelib_time_dtor(ts); +} +/* }}} */ + PHP_FUNCTION(date_timezone_set) { char *zone; |