Skip to content

Commit 64dae03

Browse files
committed
-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
1 parent a5a0706 commit 64dae03

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ static int _php3_array_walk(const void *a)
14141414
pval retval;
14151415
CLS_FETCH();
14161416

1417-
args[0] = (pval *)a;
1417+
args[0] = *((pval **)a);
14181418

14191419
call_user_function(CG(function_table), NULL, php3_array_walk_func_name, &retval, 1, args);
14201420
return 0;

ext/standard/datetime.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ static int phpday_tab[2][12] =
6060
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
6161
};
6262

63+
#define isleap(year) (((year%4) == 0 && (year%100)!=0) || (year%400)==0)
64+
6365
PHP_FUNCTION(time)
6466
{
6567
return_value->value.lval = (long) time(NULL);
@@ -142,7 +144,7 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
142144
pval *format, *timestamp;
143145
time_t the_time;
144146
struct tm *ta;
145-
int i, size = 0, length, h;
147+
int i, size = 0, length, h, beat;
146148
char tmp_buff[16];
147149

148150
switch(ARG_COUNT(ht)) {
@@ -181,14 +183,18 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
181183
break;
182184
case 'F': /* month, textual, full */
183185
case 'l': /* day (of the week), textual */
186+
case 'T': /* timezone name */
184187
size += 9;
185188
break;
189+
case 'Z': /* timezone offset in seconds */
190+
size += 6;
191+
break;
186192
case 'Y': /* year, numeric, 4 digits */
187193
size += 4;
188194
break;
189195
case 'M': /* month, textual, 3 letters */
190196
case 'D': /* day, textual, 3 letters */
191-
case 'z': /* day of the year */
197+
case 'z': /* day of the year, 1 to 366 */
192198
size += 3;
193199
break;
194200
case 'y': /* year, numeric, 2 digits */
@@ -205,12 +211,17 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
205211
case 'A': /* AM/PM */
206212
case 'a': /* am/pm */
207213
case 'S': /* standard english suffix for the day of the month (e.g. 3rd, 2nd, etc) */
214+
case 't': /* days in current month */
208215
size += 2;
209216
break;
210217
case '\\':
211218
if(i < format->value.str.len-1) {
212219
i++;
213220
}
221+
case 'L': /* boolean for leap year */
222+
case 'B': /* Swatch Beat, 3 digits */
223+
size += 3;
224+
break;
214225
case 'w': /* day of the week, numeric */
215226
default:
216227
size++;
@@ -328,10 +339,40 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
328339
}
329340
}
330341
break;
342+
case 't': /* days in current month */
343+
sprintf(tmp_buff, "%2d", phpday_tab[isleap((ta->tm_year+1900))][ta->tm_mon] );
344+
strcat(return_value->value.str.val, tmp_buff);
345+
break;
331346
case 'w': /* day of the week, numeric EXTENSION */
332347
sprintf(tmp_buff, "%01d", ta->tm_wday); /* SAFE */
333348
strcat(return_value->value.str.val, tmp_buff);
334349
break;
350+
case 'Z': /* timezone offset in seconds */
351+
#if HAVE_TM_GMTOFF
352+
sprintf(tmp_buff, "%ld", ta->tm_gmtoff );
353+
#else
354+
sprintf(tmp_buff, "%ld", timezone);
355+
#endif
356+
strcat(return_value->value.str.val, tmp_buff);
357+
break;
358+
case 'L': /* boolean for leapyear */
359+
sprintf(tmp_buff, "%d", (isleap((ta->tm_year+1900)) ? 1 : 0 ) );
360+
strcat(return_value->value.str.val, tmp_buff);
361+
break;
362+
case 'T': /* timezone name */
363+
#if HAVE_TM_ZONE
364+
strcat(return_value->value.str.val, ta->tm_zone);
365+
#else
366+
strcat(return_value->value.str.val, tzname[0]);
367+
#endif
368+
break;
369+
case 'B': /* Swatch Beat a.k.a. Internet Time */
370+
beat = (((((long)the_time)-(((long)the_time) -
371+
((((long)the_time) % 86400) + 3600))) * 10) / 864);
372+
if (beat > 999) beat = 0;
373+
sprintf(tmp_buff, "%03d", beat); /* SAFE */
374+
strcat(return_value->value.str.val, tmp_buff);
375+
break;
335376
default:
336377
length = strlen(return_value->value.str.val);
337378
return_value->value.str.val[length] = format->value.str.val[i];

main/php_version.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
/* automatically generated by configure */
2-
/* edit configure.in.in to change version number */
3-
#define PHP_VERSION "4.0b2-dev"
1+
#define PHP_VERSION "4.0B1"

0 commit comments

Comments
 (0)