Bug #1529: gmmktime is broken
| From: | egon at tradeservices dot com | Date: | Fri, 11 Jun 1999 19:30:00 +0000 |
| Subject: | Bug #1529: gmmktime is broken | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6832@lists.php.net to get a copy of this message | ||
From: egon@tradeservices.com
Operating system: Linux
PHP version: 3.0.9
PHP Bug Type: Misbehaving function
Bug description: gmmktime is broken
in functions/datetime.c, the code for translate to GMT is broken. The (I think) fixed version would
look like this:
void _php3_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm)
{
pval *arguments[6];
struct tm ta, *tn;
time_t t;
int i, gmadjust=0,arg_count = ARG_COUNT(ht);
if (arg_count > 6 || getParametersArray(ht, arg_count, arguments) == FAI
LURE) {
WRONG_PARAM_COUNT;
}
/* convert supplied arguments to longs */
for (i = 0; i < arg_count; i++) {
convert_to_long(arguments[i]);
}
t=time(NULL);
#if HAVE_TZSET
tzset();
#endif
tn = localtime(&t);
memcpy(&ta,tn,sizeof(struct tm));
ta.tm_isdst = -1;
switch(arg_count) {
case 6:
ta.tm_year = arguments[5]->value.lval - ((arguments[5]->value.lv
al > 1000) ? 1900 : 0);
/* fall-through */
case 5:
ta.tm_mday = arguments[4]->value.lval;
/* fall-through */
case 4:
ta.tm_mon = arguments[3]->value.lval - 1;
/* fall-through */
case 3:
ta.tm_sec = arguments[2]->value.lval;
/* fall-through */
case 2:
ta.tm_min = arguments[1]->value.lval;
/* fall-through */
case 1:
ta.tm_hour = arguments[0]->value.lval/* - gmadjust*/;
case 0:
break;
}
t=mktime(&ta); /* Need to do this because of Daylight savings */
tn = localtime(&t);
if (gm) {
#if HAVE_TM_GMTOFF
gmadjust=(tn->tm_gmtoff)/3600;
#else
gmadjust=timezone/3600;
#endif
}
ta.tm_hour+=gmadjust;
return_value->value.lval = mktime(&ta);
return_value->type = IS_LONG;
}