1999-04-17 08:37:12 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| PHP version 4.0 |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-01-01 09:32:05 +08:00
|
|
|
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 23:34:45 +08:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 23:34:45 +08:00
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 21:13:16 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
| Rasmus Lerdorf <rasmus@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "zend_operators.h"
|
|
|
|
#include "datetime.h"
|
|
|
|
#include "php_globals.h"
|
|
|
|
|
|
|
|
#include <time.h>
|
1999-07-24 10:43:22 +08:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
1999-04-17 08:37:12 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2000-08-21 17:50:53 +08:00
|
|
|
#include "php_parsedate.h"
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
char *mon_full_names[] =
|
|
|
|
{
|
|
|
|
"January", "February", "March", "April",
|
|
|
|
"May", "June", "July", "August",
|
|
|
|
"September", "October", "November", "December"
|
|
|
|
};
|
|
|
|
char *mon_short_names[] =
|
|
|
|
{
|
|
|
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
|
|
|
};
|
|
|
|
char *day_full_names[] =
|
|
|
|
{
|
|
|
|
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
|
|
|
|
};
|
|
|
|
char *day_short_names[] =
|
|
|
|
{
|
|
|
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
|
|
|
};
|
|
|
|
|
2000-01-01 10:22:01 +08:00
|
|
|
#if !defined(HAVE_TM_ZONE) && !defined(_TIMEZONE) && !defined(HAVE_DECLARED_TIMEZONE)
|
2000-06-16 06:23:08 +08:00
|
|
|
extern time_t timezone;
|
2000-06-10 04:18:36 +08:00
|
|
|
extern int daylight;
|
1999-04-17 08:37:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int phpday_tab[2][12] =
|
|
|
|
{
|
|
|
|
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
|
|
|
|
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
|
|
|
|
};
|
|
|
|
|
1999-07-22 23:15:41 +08:00
|
|
|
#define isleap(year) (((year%4) == 0 && (year%100)!=0) || (year%400)==0)
|
|
|
|
|
2000-03-29 04:26:02 +08:00
|
|
|
/* {{{ proto int time(void)
|
|
|
|
Return current UNIX timestamp */
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(time)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
2000-03-28 02:11:33 +08:00
|
|
|
RETURN_LONG((long)time(NULL));
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-03-29 04:26:02 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-18 12:01:20 +08:00
|
|
|
void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-12-20 09:23:15 +08:00
|
|
|
pval **arguments[7];
|
1999-11-27 00:29:00 +08:00
|
|
|
struct tm *ta, tmbuf;
|
1999-04-17 08:37:12 +08:00
|
|
|
time_t t;
|
2000-06-06 03:47:54 +08:00
|
|
|
int i, gmadjust, seconds, arg_count = ZEND_NUM_ARGS();
|
2000-06-16 00:24:10 +08:00
|
|
|
int is_dst = -1;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-20 09:23:15 +08:00
|
|
|
if (arg_count > 7 || zend_get_parameters_array_ex(arg_count,arguments) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
/* convert supplied arguments to longs */
|
|
|
|
for (i = 0; i < arg_count; i++) {
|
1999-12-20 09:23:15 +08:00
|
|
|
convert_to_long_ex(arguments[i]);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-08-29 00:19:14 +08:00
|
|
|
t = time(NULL);
|
1999-06-28 05:45:06 +08:00
|
|
|
#ifdef HAVE_TZSET
|
1999-04-25 04:48:12 +08:00
|
|
|
tzset();
|
|
|
|
#endif
|
1999-08-29 00:19:14 +08:00
|
|
|
/*
|
|
|
|
** Set default time parameters with local time values,
|
|
|
|
** EVEN when some GMT time parameters are specified!
|
|
|
|
** This may give strange result, with PHP gmmktime(0,0,0),
|
|
|
|
** which is assumed to return GMT midnight time
|
|
|
|
** for today (in localtime), so that the result time may be
|
|
|
|
** AFTER or BEFORE the current time.
|
|
|
|
** May be we should initialize tn using gmtime(), so that
|
|
|
|
** default parameters for PHP gmmktime would be the current
|
|
|
|
** GMT time values...
|
|
|
|
*/
|
2000-05-04 18:38:17 +08:00
|
|
|
ta = php_localtime_r(&t, &tmbuf);
|
1999-10-08 11:08:44 +08:00
|
|
|
|
|
|
|
/* Let DST be unknown. mktime() should compute the right value
|
|
|
|
** and behave correctly. Unless the user overrides this.
|
|
|
|
*/
|
|
|
|
ta->tm_isdst = -1;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-08-29 00:19:14 +08:00
|
|
|
/*
|
|
|
|
** Now change date values with supplied parameters.
|
|
|
|
*/
|
1999-04-17 08:37:12 +08:00
|
|
|
switch(arg_count) {
|
1999-06-28 05:45:06 +08:00
|
|
|
case 7:
|
2000-06-16 00:24:10 +08:00
|
|
|
ta->tm_isdst = is_dst = (*arguments[6])->value.lval;
|
1999-08-29 00:19:14 +08:00
|
|
|
/* fall-through */
|
1999-04-17 08:37:12 +08:00
|
|
|
case 6:
|
2000-08-01 19:16:20 +08:00
|
|
|
/* special case:
|
|
|
|
a zero in year, month and day is considered illegal
|
|
|
|
as it would be interpreted as 30.11.1999 otherwise
|
|
|
|
*/
|
|
|
|
if ( ( (*arguments[5])->value.lval==0)
|
|
|
|
&&((*arguments[4])->value.lval==0)
|
|
|
|
&&((*arguments[3])->value.lval==0)
|
|
|
|
) {
|
|
|
|
RETURN_LONG(-1);
|
|
|
|
}
|
|
|
|
|
1999-08-29 00:19:14 +08:00
|
|
|
/*
|
|
|
|
** Accept parameter in range 0..1000 interpreted as 1900..2900
|
|
|
|
** (if 100 is given, it means year 2000)
|
|
|
|
** or in range 1001..9999 interpreted as is (this will store
|
|
|
|
** negative tm_year for years in range 1001..1899)
|
|
|
|
** This function is then Y2K ready, and accepts a wide range of
|
|
|
|
** dates including the whole gregorian calendar.
|
|
|
|
** But it cannot represent ancestral dates prior to year 1001.
|
2000-02-01 01:22:17 +08:00
|
|
|
** Additionally, input parameters of 0..70 are mapped to 100..170
|
1999-08-29 00:19:14 +08:00
|
|
|
*/
|
2000-02-01 01:22:17 +08:00
|
|
|
if ((*arguments[5])->value.lval < 70)
|
|
|
|
ta->tm_year = (*arguments[5])->value.lval + 100;
|
|
|
|
else
|
|
|
|
ta->tm_year = (*arguments[5])->value.lval
|
|
|
|
- (((*arguments[5])->value.lval > 1000) ? 1900 : 0);
|
1999-04-17 08:37:12 +08:00
|
|
|
/* fall-through */
|
|
|
|
case 5:
|
1999-12-20 09:23:15 +08:00
|
|
|
ta->tm_mday = (*arguments[4])->value.lval;
|
1999-04-17 08:37:12 +08:00
|
|
|
/* fall-through */
|
|
|
|
case 4:
|
1999-12-20 09:23:15 +08:00
|
|
|
ta->tm_mon = (*arguments[3])->value.lval - 1;
|
1999-04-17 08:37:12 +08:00
|
|
|
/* fall-through */
|
|
|
|
case 3:
|
1999-12-20 09:23:15 +08:00
|
|
|
ta->tm_sec = (*arguments[2])->value.lval;
|
1999-04-17 08:37:12 +08:00
|
|
|
/* fall-through */
|
|
|
|
case 2:
|
1999-12-20 09:23:15 +08:00
|
|
|
ta->tm_min = (*arguments[1])->value.lval;
|
1999-04-17 08:37:12 +08:00
|
|
|
/* fall-through */
|
|
|
|
case 1:
|
1999-12-20 09:23:15 +08:00
|
|
|
ta->tm_hour = (*arguments[0])->value.lval;
|
1999-08-29 00:19:14 +08:00
|
|
|
/* fall-through */
|
1999-04-17 08:37:12 +08:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
}
|
1999-06-15 20:31:29 +08:00
|
|
|
|
1999-10-08 11:08:44 +08:00
|
|
|
seconds = mktime(ta);
|
2000-06-16 00:24:10 +08:00
|
|
|
if (is_dst == -1)
|
|
|
|
is_dst = ta->tm_isdst;
|
1999-10-08 11:08:44 +08:00
|
|
|
|
1999-06-15 20:31:29 +08:00
|
|
|
if (gm) {
|
|
|
|
#if HAVE_TM_GMTOFF
|
1999-08-29 00:19:14 +08:00
|
|
|
/*
|
1999-10-08 11:08:44 +08:00
|
|
|
** mktime(ta) very nicely just filled ta->tm_gmtoff with
|
|
|
|
** the exactly right value for adjustment if we want GMT.
|
1999-08-29 00:19:14 +08:00
|
|
|
*/
|
1999-10-08 11:08:44 +08:00
|
|
|
gmadjust = ta->tm_gmtoff;
|
1999-06-15 20:31:29 +08:00
|
|
|
#else
|
1999-08-29 00:19:14 +08:00
|
|
|
/*
|
2000-06-16 00:24:10 +08:00
|
|
|
** If correcting for daylight savings time, we set the adjustment to
|
2000-06-16 06:23:08 +08:00
|
|
|
** the value of timezone - 3600 seconds. Otherwise, we need to overcorrect and
|
|
|
|
** set the adjustment to the main timezone + 3600 seconds.
|
1999-08-29 00:19:14 +08:00
|
|
|
*/
|
2000-06-16 06:23:08 +08:00
|
|
|
gmadjust = -(is_dst ? timezone - 3600 : timezone + 3600);
|
1999-06-15 20:31:29 +08:00
|
|
|
#endif
|
1999-10-08 11:08:44 +08:00
|
|
|
seconds += gmadjust;
|
1999-06-15 20:31:29 +08:00
|
|
|
}
|
|
|
|
|
1999-10-08 11:08:44 +08:00
|
|
|
RETURN_LONG(seconds);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
2000-06-26 01:55:13 +08:00
|
|
|
/* {{{ proto int mktime(int hour, int min, int sec, int mon, int day, int year)
|
2000-03-29 04:26:02 +08:00
|
|
|
Get UNIX timestamp for a date */
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(mktime)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-12-18 12:01:20 +08:00
|
|
|
php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-03-29 04:26:02 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-06-26 01:55:13 +08:00
|
|
|
/* {{{ proto int gmmktime(int hour, int min, int sec, int mon, int day, int year)
|
2000-03-29 04:26:02 +08:00
|
|
|
Get UNIX timestamp for a GMT date */
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(gmmktime)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-12-18 12:01:20 +08:00
|
|
|
php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-03-29 04:26:02 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
static void
|
1999-12-18 12:01:20 +08:00
|
|
|
php_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-12-20 09:23:15 +08:00
|
|
|
pval **format, **timestamp;
|
1999-04-17 08:37:12 +08:00
|
|
|
time_t the_time;
|
1999-11-27 00:29:00 +08:00
|
|
|
struct tm *ta, tmbuf;
|
1999-07-22 23:15:41 +08:00
|
|
|
int i, size = 0, length, h, beat;
|
2001-01-03 04:26:51 +08:00
|
|
|
char tmp_buff[32];
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-06-06 03:47:54 +08:00
|
|
|
switch(ZEND_NUM_ARGS()) {
|
1999-04-17 08:37:12 +08:00
|
|
|
case 1:
|
1999-12-20 09:23:15 +08:00
|
|
|
if (zend_get_parameters_ex(1, &format) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
the_time = time(NULL);
|
|
|
|
break;
|
|
|
|
case 2:
|
1999-12-20 09:23:15 +08:00
|
|
|
if (zend_get_parameters_ex(2, &format, ×tamp) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-12-20 09:23:15 +08:00
|
|
|
convert_to_long_ex(timestamp);
|
|
|
|
the_time = (*timestamp)->value.lval;
|
1999-04-17 08:37:12 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-12-20 09:23:15 +08:00
|
|
|
convert_to_string_ex(format);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
if (gm) {
|
2000-05-04 18:38:17 +08:00
|
|
|
ta = php_gmtime_r(&the_time, &tmbuf);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
2000-05-04 18:38:17 +08:00
|
|
|
ta = php_localtime_r(&the_time, &tmbuf);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ta) { /* that really shouldn't happen... */
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "unexpected error in date()");
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-12-20 09:23:15 +08:00
|
|
|
for (i = 0; i < (*format)->value.str.len; i++) {
|
|
|
|
switch ((*format)->value.str.val[i]) {
|
2000-11-10 05:30:03 +08:00
|
|
|
case 'r': /* rfc822 format */
|
2000-11-12 01:28:20 +08:00
|
|
|
size += 31;
|
2000-07-05 00:16:32 +08:00
|
|
|
break;
|
1999-04-17 08:37:12 +08:00
|
|
|
case 'U': /* seconds since the epoch */
|
|
|
|
size += 10;
|
|
|
|
break;
|
|
|
|
case 'F': /* month, textual, full */
|
|
|
|
case 'l': /* day (of the week), textual */
|
1999-07-22 23:15:41 +08:00
|
|
|
case 'T': /* timezone name */
|
2001-01-06 01:34:47 +08:00
|
|
|
size += 28;
|
1999-04-17 08:37:12 +08:00
|
|
|
break;
|
1999-07-22 23:15:41 +08:00
|
|
|
case 'Z': /* timezone offset in seconds */
|
|
|
|
size += 6;
|
|
|
|
break;
|
2000-11-10 05:30:03 +08:00
|
|
|
case 'O': /* GMT offset in [+-]HHMM format */
|
|
|
|
size += 5;
|
|
|
|
break;
|
1999-04-17 08:37:12 +08:00
|
|
|
case 'Y': /* year, numeric, 4 digits */
|
|
|
|
size += 4;
|
|
|
|
break;
|
|
|
|
case 'M': /* month, textual, 3 letters */
|
|
|
|
case 'D': /* day, textual, 3 letters */
|
1999-07-22 23:15:41 +08:00
|
|
|
case 'z': /* day of the year, 1 to 366 */
|
2000-11-10 05:30:03 +08:00
|
|
|
case 'B': /* Swatch Beat, 3 digits */
|
1999-04-17 08:37:12 +08:00
|
|
|
size += 3;
|
|
|
|
break;
|
|
|
|
case 'y': /* year, numeric, 2 digits */
|
|
|
|
case 'm': /* month, numeric */
|
1999-07-21 03:11:32 +08:00
|
|
|
case 'n': /* month, numeric, no leading zeroes */
|
1999-04-17 08:37:12 +08:00
|
|
|
case 'd': /* day of the month, numeric */
|
|
|
|
case 'j': /* day of the month, numeric, no leading zeros */
|
|
|
|
case 'H': /* hour, numeric, 24 hour format */
|
|
|
|
case 'h': /* hour, numeric, 12 hour format */
|
1999-07-21 00:59:30 +08:00
|
|
|
case 'G': /* hour, numeric, 24 hour format, no leading zeroes */
|
|
|
|
case 'g': /* hour, numeric, 12 hour format, no leading zeroes */
|
1999-04-17 08:37:12 +08:00
|
|
|
case 'i': /* minutes, numeric */
|
|
|
|
case 's': /* seconds, numeric */
|
|
|
|
case 'A': /* AM/PM */
|
|
|
|
case 'a': /* am/pm */
|
|
|
|
case 'S': /* standard english suffix for the day of the month (e.g. 3rd, 2nd, etc) */
|
1999-07-22 23:15:41 +08:00
|
|
|
case 't': /* days in current month */
|
1999-04-17 08:37:12 +08:00
|
|
|
size += 2;
|
|
|
|
break;
|
|
|
|
case '\\':
|
1999-12-20 09:23:15 +08:00
|
|
|
if(i < (*format)->value.str.len-1) {
|
1999-04-17 08:37:12 +08:00
|
|
|
i++;
|
|
|
|
}
|
1999-07-22 23:15:41 +08:00
|
|
|
break;
|
2000-11-10 05:30:03 +08:00
|
|
|
case 'L': /* boolean for leap year */
|
1999-04-17 08:37:12 +08:00
|
|
|
case 'w': /* day of the week, numeric */
|
2000-03-28 02:11:33 +08:00
|
|
|
case 'I': /* DST? */
|
1999-04-17 08:37:12 +08:00
|
|
|
default:
|
|
|
|
size++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return_value->value.str.val = (char *) emalloc(size + 1);
|
|
|
|
return_value->value.str.val[0] = '\0';
|
|
|
|
|
1999-12-20 09:23:15 +08:00
|
|
|
for (i = 0; i < (*format)->value.str.len; i++) {
|
|
|
|
switch ((*format)->value.str.val[i]) {
|
1999-04-17 08:37:12 +08:00
|
|
|
case '\\':
|
1999-12-20 09:23:15 +08:00
|
|
|
if(i < (*format)->value.str.len-1) {
|
1999-04-17 08:37:12 +08:00
|
|
|
char ch[2];
|
1999-12-20 09:23:15 +08:00
|
|
|
ch[0]=(*format)->value.str.val[i+1];
|
1999-04-17 08:37:12 +08:00
|
|
|
ch[1]='\0';
|
|
|
|
strcat(return_value->value.str.val, ch);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'U': /* seconds since the epoch */
|
|
|
|
sprintf(tmp_buff, "%ld", (long)the_time); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
case 'F': /* month, textual, full */
|
|
|
|
strcat(return_value->value.str.val, mon_full_names[ta->tm_mon]);
|
|
|
|
break;
|
|
|
|
case 'l': /* day (of the week), textual, full */
|
|
|
|
strcat(return_value->value.str.val, day_full_names[ta->tm_wday]);
|
|
|
|
break;
|
|
|
|
case 'Y': /* year, numeric, 4 digits */
|
|
|
|
sprintf(tmp_buff, "%d", ta->tm_year + 1900); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
case 'M': /* month, textual, 3 letters */
|
|
|
|
strcat(return_value->value.str.val, mon_short_names[ta->tm_mon]);
|
|
|
|
break;
|
|
|
|
case 'D': /* day (of the week), textual, 3 letters */
|
|
|
|
strcat(return_value->value.str.val, day_short_names[ta->tm_wday]);
|
|
|
|
break;
|
|
|
|
case 'z': /* day (of the year) */
|
|
|
|
sprintf(tmp_buff, "%d", ta->tm_yday); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
case 'y': /* year, numeric, 2 digits */
|
|
|
|
sprintf(tmp_buff, "%02d", ((ta->tm_year)%100)); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
case 'm': /* month, numeric */
|
|
|
|
sprintf(tmp_buff, "%02d", ta->tm_mon + 1); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
1999-07-21 03:11:32 +08:00
|
|
|
case 'n': /* month, numeric, no leading zeros */
|
|
|
|
sprintf(tmp_buff, "%d", ta->tm_mon + 1); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
1999-04-17 08:37:12 +08:00
|
|
|
case 'd': /* day of the month, numeric */
|
|
|
|
sprintf(tmp_buff, "%02d", ta->tm_mday); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
sprintf(tmp_buff, "%d", ta->tm_mday); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
case 'H': /* hour, numeric, 24 hour format */
|
|
|
|
sprintf(tmp_buff, "%02d", ta->tm_hour); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
case 'h': /* hour, numeric, 12 hour format */
|
|
|
|
h = ta->tm_hour % 12; if (h==0) h = 12;
|
|
|
|
sprintf(tmp_buff, "%02d", h); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
1999-07-21 00:59:30 +08:00
|
|
|
case 'G': /* hour, numeric, 24 hour format, no leading zeros */
|
|
|
|
sprintf(tmp_buff, "%d", ta->tm_hour); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
case 'g': /* hour, numeric, 12 hour format, no leading zeros */
|
|
|
|
h = ta->tm_hour % 12; if (h==0) h = 12;
|
|
|
|
sprintf(tmp_buff, "%d", h); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
1999-04-17 08:37:12 +08:00
|
|
|
case 'i': /* minutes, numeric */
|
|
|
|
sprintf(tmp_buff, "%02d", ta->tm_min); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
case 's': /* seconds, numeric */
|
|
|
|
sprintf(tmp_buff, "%02d", ta->tm_sec); /* SAFE */
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
case 'A': /* AM/PM */
|
|
|
|
strcat(return_value->value.str.val, (ta->tm_hour >= 12 ? "PM" : "AM"));
|
|
|
|
break;
|
|
|
|
case 'a': /* am/pm */
|
|
|
|
strcat(return_value->value.str.val, (ta->tm_hour >= 12 ? "pm" : "am"));
|
|
|
|
break;
|
|
|
|
case 'S': /* standard english suffix, e.g. 2nd/3rd for the day of the month */
|
|
|
|
if (ta->tm_mday >= 10 && ta->tm_mday <= 19) {
|
|
|
|
strcat(return_value->value.str.val, "th");
|
|
|
|
} else {
|
|
|
|
switch (ta->tm_mday % 10) {
|
|
|
|
case 1:
|
|
|
|
strcat(return_value->value.str.val, "st");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
strcat(return_value->value.str.val, "nd");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
strcat(return_value->value.str.val, "rd");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcat(return_value->value.str.val, "th");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-07-22 23:15:41 +08:00
|
|
|
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;
|
1999-04-17 08:37:12 +08:00
|
|
|
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;
|
2000-07-05 00:16:32 +08:00
|
|
|
case 'O': /* GMT offset in [+-]HHMM format */
|
|
|
|
#if HAVE_TM_GMTOFF
|
|
|
|
sprintf(tmp_buff, "%c%02d%02d", (ta->tm_gmtoff < 0) ? '-' : '+', abs(ta->tm_gmtoff / 3600), abs( ta->tm_gmtoff % 3600));
|
|
|
|
#else
|
|
|
|
sprintf(tmp_buff, "%c%02d%02d", ((ta->tm_isdst ? timezone - 3600:timezone)<0)?'-':'+',abs((ta->tm_isdst ? timezone - 3600 : timezone) / 3600), abs((ta->tm_isdst ? timezone - 3600 : timezone) % 3600));
|
|
|
|
#endif
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
1999-07-22 23:15:41 +08:00
|
|
|
case 'Z': /* timezone offset in seconds */
|
|
|
|
#if HAVE_TM_GMTOFF
|
2000-06-16 00:24:10 +08:00
|
|
|
sprintf(tmp_buff, "%ld", ta->tm_gmtoff);
|
1999-07-22 23:15:41 +08:00
|
|
|
#else
|
2000-06-16 06:23:08 +08:00
|
|
|
sprintf(tmp_buff, "%ld", ta->tm_isdst ? timezone - 3600 : timezone);
|
1999-07-22 23:15:41 +08:00
|
|
|
#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;
|
2000-03-28 02:11:33 +08:00
|
|
|
case 'I':
|
|
|
|
sprintf(tmp_buff, "%d", ta->tm_isdst);
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
2000-11-10 05:30:03 +08:00
|
|
|
case 'r':
|
|
|
|
#if HAVE_TM_GMTOFF
|
2000-11-12 01:28:20 +08:00
|
|
|
sprintf(tmp_buff, "%3s, %2d %3s %04d %02d:%02d:%02d %c%02d%02d",
|
2000-11-10 05:30:03 +08:00
|
|
|
day_short_names[ta->tm_wday],
|
|
|
|
ta->tm_mday,
|
|
|
|
mon_short_names[ta->tm_mon],
|
2000-11-12 01:28:20 +08:00
|
|
|
ta->tm_year + 1900,
|
2000-11-10 05:30:03 +08:00
|
|
|
ta->tm_hour,
|
|
|
|
ta->tm_min,
|
|
|
|
ta->tm_sec,
|
|
|
|
(ta->tm_gmtoff < 0) ? '-' : '+',
|
|
|
|
abs(ta->tm_gmtoff / 3600),
|
|
|
|
abs( ta->tm_gmtoff % 3600)
|
|
|
|
);
|
|
|
|
#else
|
2000-11-12 01:28:20 +08:00
|
|
|
sprintf(tmp_buff, "%3s, %2d %3s %04d %02d:%02d:%02d %c%02d%02d",
|
2000-11-10 05:30:03 +08:00
|
|
|
day_short_names[ta->tm_wday],
|
|
|
|
ta->tm_mday,
|
|
|
|
mon_short_names[ta->tm_mon],
|
2000-11-12 01:28:20 +08:00
|
|
|
ta->tm_year + 1900,
|
2000-11-10 05:30:03 +08:00
|
|
|
ta->tm_hour,
|
|
|
|
ta->tm_min,
|
|
|
|
ta->tm_sec,
|
|
|
|
((ta->tm_isdst ? timezone - 3600 : timezone) < 0) ? '-' : '+',
|
|
|
|
abs((ta->tm_isdst ? timezone - 3600 : timezone) / 3600),
|
|
|
|
abs((ta->tm_isdst ? timezone - 3600 : timezone) % 3600)
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
strcat(return_value->value.str.val, tmp_buff);
|
|
|
|
break;
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
default:
|
|
|
|
length = strlen(return_value->value.str.val);
|
1999-12-20 09:23:15 +08:00
|
|
|
return_value->value.str.val[length] = (*format)->value.str.val[i];
|
1999-04-17 08:37:12 +08:00
|
|
|
return_value->value.str.val[length + 1] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return_value->value.str.len = strlen(return_value->value.str.val);
|
|
|
|
return_value->type = IS_STRING;
|
|
|
|
}
|
|
|
|
|
2000-03-29 04:26:02 +08:00
|
|
|
/* {{{ proto string date(string format [, int timestamp])
|
|
|
|
Format a local time/date */
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(date)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-12-18 12:01:20 +08:00
|
|
|
php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-03-29 04:26:02 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-03-29 04:26:02 +08:00
|
|
|
/* {{{ proto string gmdate(string format [, int timestamp])
|
|
|
|
Format a GMT/CUT date/time */
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(gmdate)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-12-18 12:01:20 +08:00
|
|
|
php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-03-29 04:26:02 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-03-29 04:47:47 +08:00
|
|
|
/* {{{ proto array localtime([int timestamp [, bool associative_array]])
|
|
|
|
Returns the results of the C system call localtime as an associative array if the associative_array argument is set to 1 other wise it is a regular array */
|
2000-03-29 02:16:41 +08:00
|
|
|
PHP_FUNCTION(localtime)
|
|
|
|
{
|
|
|
|
zval **timestamp_arg, **assoc_array_arg;
|
|
|
|
struct tm *ta, tmbuf;
|
|
|
|
time_t timestamp;
|
|
|
|
int assoc_array = 0;
|
2000-06-06 03:47:54 +08:00
|
|
|
int arg_count = ZEND_NUM_ARGS();
|
2000-03-29 02:16:41 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2000-05-04 18:38:17 +08:00
|
|
|
ta = php_localtime_r(×tamp, &tmbuf);
|
2000-03-29 02:16:41 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2000-03-29 04:26:02 +08:00
|
|
|
/* }}} */
|
2000-03-29 02:16:41 +08:00
|
|
|
|
2000-03-29 04:26:02 +08:00
|
|
|
/* {{{ proto array getdate([int timestamp])
|
|
|
|
Get date/time information */
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(getdate)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-12-20 09:23:15 +08:00
|
|
|
pval **timestamp_arg;
|
1999-11-27 00:29:00 +08:00
|
|
|
struct tm *ta, tmbuf;
|
1999-04-17 08:37:12 +08:00
|
|
|
time_t timestamp;
|
|
|
|
|
2000-06-06 03:47:54 +08:00
|
|
|
if (ZEND_NUM_ARGS() == 0) {
|
1999-04-17 08:37:12 +08:00
|
|
|
timestamp = time(NULL);
|
2000-06-06 03:47:54 +08:00
|
|
|
} else if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1,×tamp_arg) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
} else {
|
1999-12-20 09:23:15 +08:00
|
|
|
convert_to_long_ex(timestamp_arg);
|
|
|
|
timestamp = (*timestamp_arg)->value.lval;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
2000-05-04 18:38:17 +08:00
|
|
|
ta = php_localtime_r(×tamp, &tmbuf);
|
1999-04-17 08:37:12 +08:00
|
|
|
if (!ta) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "Cannot perform date calculation");
|
1999-04-17 08:37:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (array_init(return_value) == FAILURE) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_ERROR, "Unable to initialize array");
|
1999-04-17 08:37:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
add_assoc_long(return_value, "seconds", ta->tm_sec);
|
|
|
|
add_assoc_long(return_value, "minutes", ta->tm_min);
|
|
|
|
add_assoc_long(return_value, "hours", ta->tm_hour);
|
|
|
|
add_assoc_long(return_value, "mday", ta->tm_mday);
|
|
|
|
add_assoc_long(return_value, "wday", ta->tm_wday);
|
|
|
|
add_assoc_long(return_value, "mon", ta->tm_mon + 1);
|
|
|
|
add_assoc_long(return_value, "year", ta->tm_year + 1900);
|
|
|
|
add_assoc_long(return_value, "yday", ta->tm_yday);
|
|
|
|
add_assoc_string(return_value, "weekday", day_full_names[ta->tm_wday], 1);
|
|
|
|
add_assoc_string(return_value, "month", mon_full_names[ta->tm_mon], 1);
|
|
|
|
add_index_long(return_value, 0, timestamp);
|
|
|
|
}
|
2000-03-29 04:26:02 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
/* Return date string in standard format for http headers */
|
1999-12-18 12:01:20 +08:00
|
|
|
char *php_std_date(time_t t)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-11-27 00:29:00 +08:00
|
|
|
struct tm *tm1, tmbuf;
|
1999-04-17 08:37:12 +08:00
|
|
|
char *str;
|
|
|
|
PLS_FETCH();
|
|
|
|
|
2000-05-04 18:38:17 +08:00
|
|
|
tm1 = php_gmtime_r(&t, &tmbuf);
|
1999-04-17 08:37:12 +08:00
|
|
|
str = emalloc(81);
|
|
|
|
if (PG(y2k_compliance)) {
|
2000-07-14 09:08:59 +08:00
|
|
|
snprintf(str, 80, "%s, %02d-%s-%04d %02d:%02d:%02d GMT",
|
2000-02-26 00:45:52 +08:00
|
|
|
day_short_names[tm1->tm_wday],
|
1999-04-17 08:37:12 +08:00
|
|
|
tm1->tm_mday,
|
|
|
|
mon_short_names[tm1->tm_mon],
|
|
|
|
tm1->tm_year+1900,
|
|
|
|
tm1->tm_hour, tm1->tm_min, tm1->tm_sec);
|
|
|
|
} else {
|
|
|
|
snprintf(str, 80, "%s, %02d-%s-%02d %02d:%02d:%02d GMT",
|
2000-07-14 09:08:59 +08:00
|
|
|
day_short_names[tm1->tm_wday],
|
1999-04-17 08:37:12 +08:00
|
|
|
tm1->tm_mday,
|
|
|
|
mon_short_names[tm1->tm_mon],
|
|
|
|
((tm1->tm_year)%100),
|
|
|
|
tm1->tm_hour, tm1->tm_min, tm1->tm_sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
str[79]=0;
|
|
|
|
return (str);
|
|
|
|
}
|
|
|
|
|
2000-03-29 04:26:02 +08:00
|
|
|
|
|
|
|
/* {{{ proto bool checkdate(int month, int day, int year)
|
2000-09-03 12:09:48 +08:00
|
|
|
Returns true(1) if it is a valid date in gregorian calendar */
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(checkdate)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-12-20 09:23:15 +08:00
|
|
|
pval **month, **day, **year;
|
2000-06-15 04:31:31 +08:00
|
|
|
int m, d, y, res=0;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-06-06 03:47:54 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 3 ||
|
1999-12-20 09:23:15 +08:00
|
|
|
zend_get_parameters_ex(3, &month, &day, &year) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2000-06-15 04:31:31 +08:00
|
|
|
|
|
|
|
if((*year)->type == IS_STRING) {
|
|
|
|
res = is_numeric_string((*year)->value.str.val, (*year)->value.str.len, NULL, NULL);
|
|
|
|
if(res!=IS_LONG && res !=IS_DOUBLE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-06-15 00:35:48 +08:00
|
|
|
}
|
1999-12-20 09:23:15 +08:00
|
|
|
convert_to_long_ex(day);
|
|
|
|
convert_to_long_ex(month);
|
|
|
|
convert_to_long_ex(year);
|
|
|
|
y = (*year)->value.lval;
|
|
|
|
m = (*month)->value.lval;
|
|
|
|
d = (*day)->value.lval;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-09-03 12:09:48 +08:00
|
|
|
if (y < 1 || y > 32767) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if (m < 1 || m > 12) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if (d < 1 || d > phpday_tab[isleap(y)][m - 1]) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE; /* True : This month,day,year arguments are valid */
|
|
|
|
}
|
2000-03-29 04:26:02 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
#if HAVE_STRFTIME
|
2000-03-29 04:26:02 +08:00
|
|
|
void _php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-12-20 09:23:15 +08:00
|
|
|
pval **format_arg, **timestamp_arg;
|
1999-04-17 08:37:12 +08:00
|
|
|
char *format,*buf;
|
|
|
|
time_t timestamp;
|
1999-11-27 00:29:00 +08:00
|
|
|
struct tm *ta, tmbuf;
|
1999-04-22 01:11:01 +08:00
|
|
|
int max_reallocs = 5;
|
1999-04-17 08:37:12 +08:00
|
|
|
size_t buf_len=64, real_len;
|
|
|
|
|
2000-06-06 03:47:54 +08:00
|
|
|
switch (ZEND_NUM_ARGS()) {
|
1999-04-17 08:37:12 +08:00
|
|
|
case 1:
|
1999-12-20 09:23:15 +08:00
|
|
|
if (zend_get_parameters_ex(1,&format_arg)==FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
time(×tamp);
|
|
|
|
break;
|
|
|
|
case 2:
|
1999-12-20 09:23:15 +08:00
|
|
|
if (zend_get_parameters_ex(2, &format_arg,×tamp_arg)==FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-12-20 09:23:15 +08:00
|
|
|
convert_to_long_ex(timestamp_arg);
|
|
|
|
timestamp = (*timestamp_arg)->value.lval;
|
1999-04-17 08:37:12 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-12-20 09:23:15 +08:00
|
|
|
convert_to_string_ex(format_arg);
|
|
|
|
if ((*format_arg)->value.str.len==0) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-06-15 06:11:10 +08:00
|
|
|
if (timestamp < 0) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-12-20 09:23:15 +08:00
|
|
|
format = (*format_arg)->value.str.val;
|
2000-03-29 04:26:02 +08:00
|
|
|
if (gm) {
|
2000-05-04 18:38:17 +08:00
|
|
|
ta = php_gmtime_r(×tamp, &tmbuf);
|
2000-03-29 04:26:02 +08:00
|
|
|
} else {
|
2000-05-04 18:38:17 +08:00
|
|
|
ta = php_localtime_r(×tamp, &tmbuf);
|
2000-03-29 04:26:02 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
buf = (char *) emalloc(buf_len);
|
|
|
|
while ((real_len=strftime(buf,buf_len,format,ta))==buf_len || real_len==0) {
|
|
|
|
buf_len *= 2;
|
|
|
|
buf = (char *) erealloc(buf, buf_len);
|
1999-04-22 01:11:01 +08:00
|
|
|
if(!--max_reallocs) break;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
1999-04-22 01:11:01 +08:00
|
|
|
if(real_len && real_len != buf_len) {
|
|
|
|
buf = (char *) erealloc(buf,real_len+1);
|
|
|
|
RETURN_STRINGL(buf, real_len, 0);
|
|
|
|
}
|
|
|
|
efree(buf);
|
|
|
|
RETURN_FALSE;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-03-29 04:26:02 +08:00
|
|
|
/* {{{ proto string strftime(string format [, int timestamp])
|
|
|
|
Format a local time/date according to locale settings */
|
|
|
|
PHP_FUNCTION(strftime)
|
|
|
|
{
|
|
|
|
_php_strftime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto string gmstrftime(string format [, int timestamp])
|
|
|
|
Format a GMT/CUT time/date according to locale settings */
|
|
|
|
PHP_FUNCTION(gmstrftime)
|
|
|
|
{
|
|
|
|
_php_strftime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-05-28 03:27:20 +08:00
|
|
|
#endif
|
1999-07-24 03:51:27 +08:00
|
|
|
|
1999-08-02 22:31:41 +08:00
|
|
|
/* {{{ proto int strtotime(string time, int now)
|
|
|
|
Convert string representation of date and time to a timestamp */
|
1999-07-24 03:51:27 +08:00
|
|
|
PHP_FUNCTION(strtotime)
|
|
|
|
{
|
2000-06-16 00:24:10 +08:00
|
|
|
zval **z_time, **z_now;
|
|
|
|
int argc;
|
|
|
|
time_t now;
|
1999-07-24 03:51:27 +08:00
|
|
|
|
2000-06-16 00:24:10 +08:00
|
|
|
argc = ZEND_NUM_ARGS();
|
1999-07-24 03:51:27 +08:00
|
|
|
|
2000-06-16 00:24:10 +08:00
|
|
|
if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &z_time, &z_now)==FAILURE) {
|
1999-07-24 03:51:27 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
2000-06-16 00:24:10 +08:00
|
|
|
convert_to_string_ex(z_time);
|
|
|
|
if (argc == 2) {
|
|
|
|
convert_to_long_ex(z_now);
|
|
|
|
now = Z_LVAL_PP(z_now);
|
2000-12-08 08:12:35 +08:00
|
|
|
RETURN_LONG(php_parse_date(Z_STRVAL_PP(z_time), &now));
|
1999-07-24 03:51:27 +08:00
|
|
|
} else {
|
2000-12-08 08:12:35 +08:00
|
|
|
RETURN_LONG(php_parse_date(Z_STRVAL_PP(z_time), NULL));
|
1999-07-24 03:51:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-06-16 00:24:10 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|