summaryrefslogtreecommitdiff
path: root/ext/standard/datetime.c
diff options
context:
space:
mode:
authorDerick Rethans <derick@php.net>2005-07-03 14:27:31 +0000
committerDerick Rethans <derick@php.net>2005-07-03 14:27:31 +0000
commited02f202f017d3c1ebddb202a0fc224cce1b9e78 (patch)
treee0e39df1eeb78ea8b3fa7604094e4c39b22f47bf /ext/standard/datetime.c
parentf4b5a5195210e6e3be439386f05f909248804ae7 (diff)
downloadphp-git-ed02f202f017d3c1ebddb202a0fc224cce1b9e78.tar.gz
- Fixed bug #30096 (gmmktime does not return the corrent time).
- Re-implemented mktime and gmmktime with new date time library. - Added testcase for bug #30096, updated test cases for E_STRICT warning of is_dst parameter usage for mktime/gmmktime.
Diffstat (limited to 'ext/standard/datetime.c')
-rw-r--r--ext/standard/datetime.c204
1 files changed, 0 insertions, 204 deletions
diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c
index 9f1a9ce543..5e1933f5e9 100644
--- a/ext/standard/datetime.c
+++ b/ext/standard/datetime.c
@@ -77,210 +77,6 @@ PHP_FUNCTION(time)
}
/* }}} */
-/* {{{ php_mktime
- */
-PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm)
-{
- pval **arguments[7];
- struct tm *ta, tmbuf;
- time_t t, seconds;
- int i, gmadjust, arg_count = ZEND_NUM_ARGS();
- int is_dst = -1, chgsecs = 0;
- long val;
-
- if (arg_count > 7 || zend_get_parameters_array_ex(arg_count, arguments) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* convert supplied arguments to longs */
- for (i = 0; i < arg_count; i++) {
- convert_to_long_ex(arguments[i]);
- }
- t = time(NULL);
-#ifdef HAVE_TZSET
- tzset();
-#endif
- /*
- ** 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...
- */
- ta = php_localtime_r(&t, &tmbuf);
-
- /* Let DST be unknown. mktime() should compute the right value
- ** and behave correctly. Unless the user overrides this.
- */
- ta->tm_isdst = -1;
-
- /*
- ** Now change date values with supplied parameters.
- */
- switch(arg_count) {
- case 7: /* daylight saving time flag */
-#ifdef PHP_WIN32
- if (daylight > 0) {
- ta->tm_isdst = is_dst = Z_LVAL_PP(arguments[6]);
- } else {
- ta->tm_isdst = is_dst = 0;
- }
-#else
- ta->tm_isdst = is_dst = Z_LVAL_PP(arguments[6]);
-#endif
- /* fall-through */
- case 6: /* year */
- /* special case:
- a zero in year, month and day is considered illegal
- as it would be interpreted as 30.11.1999 otherwise
- */
- if ( ( Z_LVAL_PP(arguments[5])==0)
- &&(Z_LVAL_PP(arguments[4])==0)
- &&(Z_LVAL_PP(arguments[3])==0)
- ) {
- RETURN_LONG(-1);
- }
-
- /*
- ** 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.
- ** Additionally, input parameters of 0..70 are mapped to 100..170
- */
- if (Z_LVAL_PP(arguments[5]) < 70)
- ta->tm_year = Z_LVAL_PP(arguments[5]) + 100;
- else
- ta->tm_year = Z_LVAL_PP(arguments[5])
- - ((Z_LVAL_PP(arguments[5]) > 1000) ? 1900 : 0);
- /* fall-through */
- case 5: /* day in month (1-based) */
- val = (*arguments[4])->value.lval;
- if (val < 1) {
- chgsecs += (1-val) * 60*60*24;
- val = 1;
- }
- ta->tm_mday = val;
- /* fall-through */
- case 4: /* month (zero-based) */
- val = (*arguments[3])->value.lval - 1;
- while (val < 0) {
- val += 12; ta->tm_year--;
- }
- ta->tm_mon = val;
- /* fall-through */
- case 3: /* second */
- val = (*arguments[2])->value.lval;
- if (val < 1) {
- chgsecs += (1-val); val = 1;
- }
- ta->tm_sec = val;
- /* fall-through */
- case 2: /* minute */
- val = (*arguments[1])->value.lval;
- if (val < 1) {
- chgsecs += (1-val) * 60; val = 1;
- }
- ta->tm_min = val;
- /* fall-through */
- case 1: /* hour */
- val = (*arguments[0])->value.lval;
- /*
- We avoid midnight and a couple of hours after midnight here to work around
- various OS-level bugs in mktime and specifically daylight savings time issues
- in many mktime implementation.
- See bugs #27533 and #27719 for more info.
- */
- if (val < 4) {
- chgsecs += (4-val) * 60*60; val = 4;
- }
- ta->tm_hour = val;
- /* fall-through */
- case 0:
- break;
- }
-
- t = mktime(ta);
-
-#ifdef PHP_WIN32
- if (t - chgsecs < 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows does not support negative values for this function");
- RETURN_LONG(-1);
- }
-#endif
-
- seconds = t - chgsecs;
-
- /*
- Here we check to see if the chgsecs fuzz factor we applied caused us to
- move from dst to non-dst or vice-versa. If so we adjust accordingly to
- avoid being off by an hour on the dst changeover date.
- */
- if (is_dst == -1) {
- struct tm t1, t2;
- t1 = *localtime(&t);
- t2 = *localtime(&seconds);
-
- if (t1.tm_isdst != t2.tm_isdst) {
- seconds += (t1.tm_isdst == 1) ? 3600 : -3600;
- ta = localtime(&seconds);
- }
-
- /*
- If the user didn't specify whether the timestamp passed in was dst or not
- then we fill it in based on the dst setting at the evaluated timestamp
- at the current TZ
- */
- is_dst = ta->tm_isdst;
- }
-
- if (gm) {
-#if HAVE_TM_GMTOFF
- /*
- ** mktime(ta) very nicely just filled ta->tm_gmtoff with
- ** the exactly right value for adjustment if we want GMT.
- */
- gmadjust = ta->tm_gmtoff;
-#else
- /*
- ** If correcting for daylight savings time, we set the adjustment to
- ** the value of timezone - 3600 seconds.
- */
-#ifdef __CYGWIN__
- gmadjust = -(is_dst ? _timezone - 3600 : _timezone);
-#else
- gmadjust = -(is_dst ? timezone - 3600 : timezone);
-#endif
-#endif
- seconds += gmadjust;
- }
-
- RETURN_LONG(seconds);
-}
-/* }}} */
-
-/* {{{ proto int mktime(int hour, int min, int sec, int mon, int day, int year)
- Get UNIX timestamp for a date */
-PHP_FUNCTION(mktime)
-{
- php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto int gmmktime(int hour, int min, int sec, int mon, int day, int year)
- Get UNIX timestamp for a GMT date */
-PHP_FUNCTION(gmmktime)
-{
- php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
/* {{{ php_idate
*/
PHPAPI int php_idate(char format, int timestamp, int gm)