cvs: /php3/functions datetime.c

From: Date: Wed, 06 Oct 1999 07:46:46 +0000
Subject: cvs: /php3/functions datetime.c
Groups: php.dev 
Request: Send a blank email to php-dev+get-11562@lists.php.net to get a copy of this message
jah Wed Oct 6 03:46:46 1999 EDT Modified files: /php3/functions datetime.c Log: Fix for #2444. Also some rewriting. Please read my comments following shortly on the mailing list. Index: php3/functions/datetime.c diff -u php3/functions/datetime.c:1.74 php3/functions/datetime.c:1.75 --- php3/functions/datetime.c:1.74 Mon Aug 2 13:56:56 1999 +++ php3/functions/datetime.c Wed Oct 6 03:46:45 1999 @@ -30,7 +30,7 @@ */ -/* $Id: datetime.c,v 1.74 1999/08/02 17:56:56 musone Exp $ */ +/* $Id: datetime.c,v 1.75 1999/10/06 07:46:45 jah Exp $ */ #ifdef THREAD_SAFE @@ -99,10 +99,9 @@ void _php3_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm) { pval *arguments[7]; - struct tm ta, *tn; + struct tm *ta, *tn; time_t t; - int i, gmadjust=0,arg_count = ARG_COUNT(ht); - int gmadjust_min = 0, gmadjust_hour = 0; + int i, seconds, gmadjust=0, arg_count = ARG_COUNT(ht); if (arg_count > 7 || getParametersArray(ht, arg_count, arguments) == FAILURE) { WRONG_PARAM_COUNT; @@ -112,75 +111,63 @@ convert_to_long(arguments[i]); } - /* get the current time in seconds from epoch */ + /* get the current time in seconds from epoch */ t=time(NULL); #if HAVE_TZSET tzset(); #endif + if (gm) { /* Fix #2 */ + ta = gmtime(&t); /* Fix #2 */ + } else { /* Fix #2 */ + ta = localtime(&t); + } /* Fix #2 */ + + /* Let the system decide later whether the time is + in daylight savings time or not. Unless the user + overrides this, of course. */ + ta->tm_isdst = -1; - /* convert to a tm struct as local or gm time */ - if (gm) { - tn = gmtime(&t); - } - else { - tn = localtime(&t); - } - memcpy(&ta,tn,sizeof(struct tm)); - - /* if we're working in GMT, there's no DST, otherwise - we let the system figure it out */ - if (gm) { - ta.tm_isdst = 0; - } - else { - ta.tm_isdst = -1; - } - - /* but the user can override that, of course */ - if (arg_count > 6) { - ta.tm_isdst = arguments[6]->value.lval; - } - - /* now we apply the specified parameters to the timestamp */ + /* now we apply the specified parameters to the timestamp */ switch(arg_count) { case 7: + ta->tm_isdst = arguments[6]->value.lval; + /* fall-through */ case 6: - ta.tm_year = arguments[5]->value.lval - ((arguments[5]->value.lval > 1000) ? 1900 : 0); + ta->tm_year = arguments[5]->value.lval - ((arguments[5]->value.lval > 1000) ? 1900 : 0); /* fall-through */ case 5: - ta.tm_mday = arguments[4]->value.lval; + ta->tm_mday = arguments[4]->value.lval; /* fall-through */ case 4: - ta.tm_mon = arguments[3]->value.lval - 1; + ta->tm_mon = arguments[3]->value.lval - 1; /* fall-through */ case 3: - ta.tm_sec = arguments[2]->value.lval; + ta->tm_sec = arguments[2]->value.lval; /* fall-through */ case 2: - ta.tm_min = arguments[1]->value.lval; + ta->tm_min = arguments[1]->value.lval; /* fall-through */ case 1: - ta.tm_hour = arguments[0]->value.lval; + ta->tm_hour = arguments[0]->value.lval; case 0: break; } - /* if we're working in GMT, we need to fix the tm struct - to be in localtime before we can call mktime(). */ + seconds = mktime(ta); + + /* mktime(), which *does* modify the structure its argument points to, + very nicely just filled ta->tm_gmtoff with the right value for us to + use. So add it to seconds, if we want GMT. */ if (gm) { #if HAVE_TM_GMTOFF - gmadjust=tn->tm_gmtoff; + gmadjust = ta->tm_gmtoff; #else - gmadjust=timezone; + gmadjust = timezone; #endif - gmadjust_hour = gmadjust / 3600; - gmadjust_min = gmadjust - gmadjust_hour * 3600; - - ta.tm_hour += gmadjust_hour; - ta.tm_min += gmadjust_min; + seconds += gmadjust; } - return_value->value.lval = mktime(&ta); + return_value->value.lval = seconds; return_value->type = IS_LONG; }

« previous php.dev (#11562) next »