summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Waychison <mikew@php.net>2000-07-04 16:16:32 +0000
committerMike Waychison <mikew@php.net>2000-07-04 16:16:32 +0000
commit4604031b84c100983cd2525b4043b0dba8e2f9e9 (patch)
tree1034eb2eeb137277af3af009ba76cf658faa810b
parent23ca7b9f1ad0f82efe3760284353807a38d94533 (diff)
downloadphp-git-4604031b84c100983cd2525b4043b0dba8e2f9e9.tar.gz
(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 :)
-rw-r--r--ext/standard/datetime.c11
1 files changed, 11 insertions, 0 deletions
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);