]> granicus.if.org Git - php/commitdiff
*** empty log message ***
authorSterling Hughes <sterling@php.net>
Tue, 28 Mar 2000 18:16:41 +0000 (18:16 +0000)
committerSterling Hughes <sterling@php.net>
Tue, 28 Mar 2000 18:16:41 +0000 (18:16 +0000)
ext/standard/basic_functions.c
ext/standard/datetime.c
ext/standard/datetime.h

index 6ae12fb939be9afaea0007d124579888fe43afba..96eaced044d37abdac09b465c33d9a2013db01b4 100644 (file)
@@ -92,6 +92,7 @@ function_entry basic_functions[] = {
        PHP_FE(date,                                                                    NULL)
        PHP_FE(gmdate,                                                                  NULL)
        PHP_FE(getdate,                                                                 NULL)
+       PHP_FE(localtime,                                                               NULL)
        PHP_FE(checkdate,                                                               NULL)
 
        PHP_FE(flush,                                                                   NULL)
index 6604e21408fde1a41f88e07644f05c677a471702..44c05e6979397d1265af513af72d63cefe852c3d 100644 (file)
@@ -445,6 +445,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, &timestamp_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(&timestamp, &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)
 {
        pval **timestamp_arg;
index eaff52648ba499dbd9a99e6625a2c4a2906701b6..2e8f61f53d1ffae43d2d62d62dbbd7bec6a78493 100644 (file)
@@ -39,6 +39,7 @@ PHP_FUNCTION(mktime);
 PHP_FUNCTION(gmmktime);
 PHP_FUNCTION(date);
 PHP_FUNCTION(gmdate);
+PHP_FUNCTION(localtime);
 PHP_FUNCTION(getdate);
 PHP_FUNCTION(checkdate);
 #if HAVE_STRFTIME