gmmktime()

From: Date: Fri, 23 Jul 1999 20:38:37 +0000
Subject: gmmktime()
Groups: php.dev 
Request: Send a blank email to php-dev+get-9060@lists.php.net to get a copy of this message
Okay, after looking at the gmmktime() thing a bit more, can someone tell me why the patch below does not give more correct behavior than the current implementation? Jim

Index: functions/datetime.c =================================================================== RCS file: /repository/php3/functions/datetime.c,v retrieving revision 1.70 diff -u -r1.70 datetime.c --- functions/datetime.c 1999/07/16 18:05:00 1.70 +++ functions/datetime.c 1999/07/23 20:36:40 @@ -111,20 +111,37 @@ for (i = 0; i < arg_count; i++) { convert_to_long(arguments[i]); } + + /* get the current time in seconds from epoch */ t=time(NULL); #if HAVE_TZSET tzset(); #endif - tn = localtime(&t); + + /* 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 (gm) + + /* 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 + } + else { ta.tm_isdst = -1; + } - if (arg_count > 6) + /* 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 */ switch(arg_count) { case 7: case 6: @@ -148,9 +165,8 @@ break; } - t=mktime(&ta); /* Need to do this because of Daylight savings */ - tn = localtime(&t); - + /* if we're working in GMT, we need to fix the tm struct + to be in localtime before we can call mktime(). */ if (gm) { #if HAVE_TM_GMTOFF gmadjust=tn->tm_gmtoff;
« previous php.dev (#9060) next »