@@ -60,6 +60,8 @@ static int phpday_tab[2][12] =
60
60
{31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 }
61
61
};
62
62
63
+ #define isleap (year ) (((year%4) == 0 && (year%100)!=0) || (year%400)==0)
64
+
63
65
PHP_FUNCTION (time )
64
66
{
65
67
return_value -> value .lval = (long ) time (NULL );
@@ -142,7 +144,7 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
142
144
pval * format , * timestamp ;
143
145
time_t the_time ;
144
146
struct tm * ta ;
145
- int i , size = 0 , length , h ;
147
+ int i , size = 0 , length , h , beat ;
146
148
char tmp_buff [16 ];
147
149
148
150
switch (ARG_COUNT (ht )) {
@@ -181,14 +183,18 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
181
183
break ;
182
184
case 'F' : /* month, textual, full */
183
185
case 'l' : /* day (of the week), textual */
186
+ case 'T' : /* timezone name */
184
187
size += 9 ;
185
188
break ;
189
+ case 'Z' : /* timezone offset in seconds */
190
+ size += 6 ;
191
+ break ;
186
192
case 'Y' : /* year, numeric, 4 digits */
187
193
size += 4 ;
188
194
break ;
189
195
case 'M' : /* month, textual, 3 letters */
190
196
case 'D' : /* day, textual, 3 letters */
191
- case 'z' : /* day of the year */
197
+ case 'z' : /* day of the year, 1 to 366 */
192
198
size += 3 ;
193
199
break ;
194
200
case 'y' : /* year, numeric, 2 digits */
@@ -205,12 +211,17 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
205
211
case 'A' : /* AM/PM */
206
212
case 'a' : /* am/pm */
207
213
case 'S' : /* standard english suffix for the day of the month (e.g. 3rd, 2nd, etc) */
214
+ case 't' : /* days in current month */
208
215
size += 2 ;
209
216
break ;
210
217
case '\\' :
211
218
if (i < format -> value .str .len - 1 ) {
212
219
i ++ ;
213
220
}
221
+ case 'L' : /* boolean for leap year */
222
+ case 'B' : /* Swatch Beat, 3 digits */
223
+ size += 3 ;
224
+ break ;
214
225
case 'w' : /* day of the week, numeric */
215
226
default :
216
227
size ++ ;
@@ -328,10 +339,40 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
328
339
}
329
340
}
330
341
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 ;
331
346
case 'w' : /* day of the week, numeric EXTENSION */
332
347
sprintf (tmp_buff , "%01d" , ta -> tm_wday ); /* SAFE */
333
348
strcat (return_value -> value .str .val , tmp_buff );
334
349
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 ;
335
376
default :
336
377
length = strlen (return_value -> value .str .val );
337
378
return_value -> value .str .val [length ] = format -> value .str .val [i ];
0 commit comments