From: Andrey Hristov Date: Thu, 22 Jul 1999 15:15:41 +0000 (+0000) Subject: -Ported all remaining date() options X-Git-Tag: php-4.0b1~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=64dae03eea4a5c2bd02bf8ad562584701708867d;p=php -Ported all remaining date() options -Made array_walk() work somewhat, but it's not possible to change array values from inside the walk function yet --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 2a95586043..3f445804a0 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1414,7 +1414,7 @@ static int _php3_array_walk(const void *a) pval retval; CLS_FETCH(); - args[0] = (pval *)a; + args[0] = *((pval **)a); call_user_function(CG(function_table), NULL, php3_array_walk_func_name, &retval, 1, args); return 0; diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c index 41f6765362..99038e0bd5 100644 --- a/ext/standard/datetime.c +++ b/ext/standard/datetime.c @@ -60,6 +60,8 @@ static int phpday_tab[2][12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; +#define isleap(year) (((year%4) == 0 && (year%100)!=0) || (year%400)==0) + PHP_FUNCTION(time) { return_value->value.lval = (long) time(NULL); @@ -142,7 +144,7 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm) pval *format, *timestamp; time_t the_time; struct tm *ta; - int i, size = 0, length, h; + int i, size = 0, length, h, beat; char tmp_buff[16]; switch(ARG_COUNT(ht)) { @@ -181,14 +183,18 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm) break; case 'F': /* month, textual, full */ case 'l': /* day (of the week), textual */ + case 'T': /* timezone name */ size += 9; break; + case 'Z': /* timezone offset in seconds */ + size += 6; + break; case 'Y': /* year, numeric, 4 digits */ size += 4; break; case 'M': /* month, textual, 3 letters */ case 'D': /* day, textual, 3 letters */ - case 'z': /* day of the year */ + case 'z': /* day of the year, 1 to 366 */ size += 3; break; case 'y': /* year, numeric, 2 digits */ @@ -205,12 +211,17 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm) case 'A': /* AM/PM */ case 'a': /* am/pm */ case 'S': /* standard english suffix for the day of the month (e.g. 3rd, 2nd, etc) */ + case 't': /* days in current month */ size += 2; break; case '\\': if(i < format->value.str.len-1) { i++; } + case 'L': /* boolean for leap year */ + case 'B': /* Swatch Beat, 3 digits */ + size += 3; + break; case 'w': /* day of the week, numeric */ default: size++; @@ -328,10 +339,40 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm) } } break; + case 't': /* days in current month */ + sprintf(tmp_buff, "%2d", phpday_tab[isleap((ta->tm_year+1900))][ta->tm_mon] ); + strcat(return_value->value.str.val, tmp_buff); + break; case 'w': /* day of the week, numeric EXTENSION */ sprintf(tmp_buff, "%01d", ta->tm_wday); /* SAFE */ strcat(return_value->value.str.val, tmp_buff); break; + case 'Z': /* timezone offset in seconds */ +#if HAVE_TM_GMTOFF + sprintf(tmp_buff, "%ld", ta->tm_gmtoff ); +#else + sprintf(tmp_buff, "%ld", timezone); +#endif + strcat(return_value->value.str.val, tmp_buff); + break; + case 'L': /* boolean for leapyear */ + sprintf(tmp_buff, "%d", (isleap((ta->tm_year+1900)) ? 1 : 0 ) ); + strcat(return_value->value.str.val, tmp_buff); + break; + case 'T': /* timezone name */ +#if HAVE_TM_ZONE + strcat(return_value->value.str.val, ta->tm_zone); +#else + strcat(return_value->value.str.val, tzname[0]); +#endif + break; + case 'B': /* Swatch Beat a.k.a. Internet Time */ + beat = (((((long)the_time)-(((long)the_time) - + ((((long)the_time) % 86400) + 3600))) * 10) / 864); + if (beat > 999) beat = 0; + sprintf(tmp_buff, "%03d", beat); /* SAFE */ + strcat(return_value->value.str.val, tmp_buff); + break; default: length = strlen(return_value->value.str.val); return_value->value.str.val[length] = format->value.str.val[i]; diff --git a/main/php_version.h b/main/php_version.h index ab60bf6f9f..ee69a881fc 100644 --- a/main/php_version.h +++ b/main/php_version.h @@ -1,3 +1 @@ -/* automatically generated by configure */ -/* edit configure.in.in to change version number */ -#define PHP_VERSION "4.0b2-dev" +#define PHP_VERSION "4.0B1"