cvs: /php4/ext/standard datetime.c datetime.h basic_functions.c
| From: | Sterling Hughes | Date: | Tue, 28 Mar 2000 18:17:11 +0000 |
| Subject: | cvs: /php4/ext/standard datetime.c datetime.h basic_functions.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-12760@lists.php.net to get a copy of this message | ||
sterling Tue Mar 28 10:17:11 2000 EDT
Modified files:
/php4/ext/standard datetime.c datetime.h basic_functions.c
Log:
Index: php4/ext/standard/datetime.c
diff -u php4/ext/standard/datetime.c:1.33 php4/ext/standard/datetime.c:1.34
--- php4/ext/standard/datetime.c:1.33 Mon Mar 27 10:11:33 2000
+++ php4/ext/standard/datetime.c Tue Mar 28 10:16:41 2000
@@ -19,7 +19,7 @@
*/
-/* $Id: datetime.c,v 1.33 2000/03/27 18:11:33 sterling Exp $ */
+/* $Id: datetime.c,v 1.34 2000/03/28 18:16:41 sterling Exp $ */
#include "php.h"
@@ -443,6 +443,63 @@
PHP_FUNCTION(gmdate)
{
php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+
+PHP_FUNCTION(localtime)
+{
+ zval **timestamp_arg, **assoc_array_arg;
+ struct tm *ta, tmbuf;
+ time_t timestamp;
+ int assoc_array = 0;
+ int arg_count = ARG_COUNT(ht);
+
+ if (arg_count < 0 || arg_count > 2 ||
+ zend_get_parameters_ex(arg_count, ×tamp_arg, &assoc_array_arg) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ switch (arg_count) {
+ case 0:
+ timestamp = (long)time(NULL);
+ break;
+ case 1:
+ convert_to_long_ex(timestamp_arg);
+ timestamp = (*timestamp_arg)->value.lval;
+ break;
+ case 2:
+ convert_to_long_ex(timestamp_arg);
+ convert_to_long_ex(assoc_array_arg);
+ timestamp = (*timestamp_arg)->value.lval;
+ assoc_array = (*assoc_array_arg)->value.lval;
+ break;
+ }
+ ta = localtime_r(×tamp, &tmbuf);
+ if (array_init(return_value) == FAILURE) {
+ php_error(E_ERROR, "Cannot prepare return array from localtime");
+ RETURN_FALSE;
+ }
+
+ if (assoc_array) {
+ add_assoc_long(return_value, "tm_sec", ta->tm_sec);
+ add_assoc_long(return_value, "tm_min", ta->tm_min);
+ add_assoc_long(return_value, "tm_hour", ta->tm_hour);
+ add_assoc_long(return_value, "tm_mday", ta->tm_mday);
+ add_assoc_long(return_value, "tm_mon", ta->tm_mon);
+ add_assoc_long(return_value, "tm_year", ta->tm_year);
+ add_assoc_long(return_value, "tm_wday", ta->tm_wday);
+ add_assoc_long(return_value, "tm_yday", ta->tm_yday);
+ add_assoc_long(return_value, "tm_isdst", ta->tm_isdst);
+ } else {
+ add_next_index_long(return_value, ta->tm_sec);
+ add_next_index_long(return_value, ta->tm_min);
+ add_next_index_long(return_value, ta->tm_hour);
+ add_next_index_long(return_value, ta->tm_mday);
+ add_next_index_long(return_value, ta->tm_mon);
+ add_next_index_long(return_value, ta->tm_year);
+ add_next_index_long(return_value, ta->tm_wday);
+ add_next_index_long(return_value, ta->tm_yday);
+ add_next_index_long(return_value, ta->tm_isdst);
+ }
}
PHP_FUNCTION(getdate)
Index: php4/ext/standard/datetime.h
diff -u php4/ext/standard/datetime.h:1.4 php4/ext/standard/datetime.h:1.5
--- php4/ext/standard/datetime.h:1.4 Fri Dec 17 20:01:14 1999
+++ php4/ext/standard/datetime.h Tue Mar 28 10:16:41 2000
@@ -29,7 +29,7 @@
*/
-/* $Id: datetime.h,v 1.4 1999/12/18 04:01:14 zeev Exp $ */
+/* $Id: datetime.h,v 1.5 2000/03/28 18:16:41 sterling Exp $ */
#ifndef _DATETIME_H
#define _DATETIME_H
@@ -39,6 +39,7 @@
PHP_FUNCTION(gmmktime);
PHP_FUNCTION(date);
PHP_FUNCTION(gmdate);
+PHP_FUNCTION(localtime);
PHP_FUNCTION(getdate);
PHP_FUNCTION(checkdate);
#if HAVE_STRFTIME
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.175 php4/ext/standard/basic_functions.c:1.176
--- php4/ext/standard/basic_functions.c:1.175 Thu Mar 16 08:02:23 2000
+++ php4/ext/standard/basic_functions.c Tue Mar 28 10:16:41 2000
@@ -92,6 +92,7 @@
PHP_FE(date, NULL)
PHP_FE(gmdate, NULL)
PHP_FE(getdate, NULL)
+ PHP_FE(localtime, NULL)
PHP_FE(checkdate, NULL)
PHP_FE(flush, NULL)