]> granicus.if.org Git - php/commitdiff
(PHP date) Added new 'O' format modifier for printing out the GMT Offset in
authorMike Waychison <mikew@php.net>
Tue, 4 Jul 2000 16:16:32 +0000 (16:16 +0000)
committerMike Waychison <mikew@php.net>
Tue, 4 Jul 2000 16:16:32 +0000 (16:16 +0000)
           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 :)

ext/standard/datetime.c

index e1344a72e2a1429914addb7f19a81da3c2271386..91185c6caa1c80489dbb5c52df198bf51c215a69 100644 (file)
@@ -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);