From: Mike Waychison Date: Tue, 4 Jul 2000 16:16:32 +0000 (+0000) Subject: (PHP date) Added new 'O' format modifier for printing out the GMT Offset in X-Git-Tag: PRE_METHOD_CALL_SEPERATE_FIX_PATCH~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4604031b84c100983cd2525b4043b0dba8e2f9e9;p=php (PHP date) Added new 'O' format modifier for printing out the GMT Offset in the same manner as emails have in their Date: header. The format is similar to [+-]HHMM of offset. @- Added new 'O' format modifier that will output the GMT offset as "[+-]HHMM" @ (eg: Pacific time is -0700). This is useful for things such as Date: mail @ headers. # Um, this should have existed LONG time ago... much better than that gmt # offset in seconds modifier :) --- diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c index e1344a72e2..91185c6caa 100644 --- a/ext/standard/datetime.c +++ b/ext/standard/datetime.c @@ -236,6 +236,9 @@ php_date(INTERNAL_FUNCTION_PARAMETERS, int gm) } for (i = 0; i < (*format)->value.str.len; i++) { switch ((*format)->value.str.val[i]) { + case 'O': /* GMT offset in [+-]HHMM format */ + size += 5; + break; case 'U': /* seconds since the epoch */ size += 10; break; @@ -406,6 +409,14 @@ php_date(INTERNAL_FUNCTION_PARAMETERS, int gm) sprintf(tmp_buff, "%01d", ta->tm_wday); /* SAFE */ strcat(return_value->value.str.val, tmp_buff); break; + 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; case 'Z': /* timezone offset in seconds */ #if HAVE_TM_GMTOFF sprintf(tmp_buff, "%ld", ta->tm_gmtoff);