]> granicus.if.org Git - php/commitdiff
- Added 'c' modifier to date() which returns the date in ISO 8601 format.
authorDerick Rethans <derick@php.net>
Tue, 16 Dec 2003 22:52:48 +0000 (22:52 +0000)
committerDerick Rethans <derick@php.net>
Tue, 16 Dec 2003 22:52:48 +0000 (22:52 +0000)
NEWS
ext/standard/datetime.c
ext/standard/tests/time/date.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 0eafc4590bf329713a176803b8bd7c00620fc600..782dfd8fcfa6844e5e9ec7ff10f266f3b8cf3525 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,8 @@ PHP                                                                        NEWS
   . ext/db (Jani, Derick)
   . ext/mcal (Jani, Derick)
   . ext/qtdom (Jani, Derick)
+- Added 'c' modifier to date() which returns the date in the ISO 8601 format.
+  (Derick, Manuzhai)
 - Added MacRoman encoding support to htmlentities(). (Derick, Marcus Bointon)
 - Added possibility to call PHP functions as XSLT-functions. (Christian)
 - Added possibility to prevent PHP from registering variables when input filter
index f9f7c2a9e69401c8144ca4292425e2cf22aea1c4..47e14eddad8d7d26d3a009daecbc888195352ad7 100644 (file)
@@ -331,6 +331,9 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
                        case 'r':               /* rfc822 format */
                                size += 31;
                                break;
+                       case 'c':               /* iso8601 date (Dublin Core Date) */
+                               size += 25;
+                               break;
                        case 'U':               /* seconds since the epoch */
                                size += 10;
                                break;
@@ -557,8 +560,8 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
                                strcat(Z_STRVAL_P(return_value), tmp_buff);
                                break;
                        case 'r':
-#if HAVE_TM_GMTOFF                             
-                               sprintf(tmp_buff, "%3s, %2d %3s %04d %02d:%02d:%02d %c%02d%02d", 
+#if HAVE_TM_GMTOFF
+                               sprintf(tmp_buff, "%3s, %2d %3s %04d %02d:%02d:%02d %c%02d%02d",
                                        day_short_names[ta->tm_wday],
                                        ta->tm_mday,
                                        mon_short_names[ta->tm_mon],
@@ -571,7 +574,7 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
                                        abs( (ta->tm_gmtoff % 3600) / 60 )
                                );
 #else
-                               sprintf(tmp_buff, "%3s, %2d %3s %04d %02d:%02d:%02d %c%02d%02d", 
+                               sprintf(tmp_buff, "%3s, %2d %3s %04d %02d:%02d:%02d %c%02d%02d",
                                        day_short_names[ta->tm_wday],
                                        ta->tm_mday,
                                        mon_short_names[ta->tm_mon],
@@ -583,6 +586,34 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
                                        abs((ta->tm_isdst ? tzone - 3600 : tzone) / 3600),
                                        abs( ((ta->tm_isdst ? tzone - 3600 : tzone) % 3600) / 60 )
                                );
+#endif
+                               strcat(Z_STRVAL_P(return_value), tmp_buff);
+                               break;
+                       case 'c':
+#if HAVE_TM_GMTOFF
+                               sprintf(tmp_buff, "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
+                                       ta->tm_year + YEAR_BASE,
+                                       ta->tm_mon + 1,
+                                       ta->tm_mday,
+                                       ta->tm_hour,
+                                       ta->tm_min,
+                                       ta->tm_sec,
+                                       (ta->tm_gmtoff < 0) ? '-' : '+',
+                                       abs(ta->tm_gmtoff / 3600),
+                                       abs( (ta->tm_gmtoff % 3600) / 60 )
+                               );
+#else
+                               sprintf(tmp_buff, "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
+                                       ta->tm_year + YEAR_BASE,
+                                       ta->tm_mon + 1,
+                                       ta->tm_mday,
+                                       ta->tm_hour,
+                                       ta->tm_min,
+                                       ta->tm_sec,
+                                       ((ta->tm_isdst ? tzone - 3600 : tzone) > 0) ? '-' : '+',
+                                       abs((ta->tm_isdst ? tzone - 3600 : tzone) / 3600),
+                                       abs( ((ta->tm_isdst ? tzone - 3600 : tzone) % 3600) / 60 )
+                               );
 #endif
                                strcat(Z_STRVAL_P(return_value), tmp_buff);
                                break;
diff --git a/ext/standard/tests/time/date.phpt b/ext/standard/tests/time/date.phpt
new file mode 100644 (file)
index 0000000..87cae0b
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+date() function
+--FILE--
+<?php
+$tmp = "cr";
+putenv ("TZ=GMT0");
+
+for($a = 0;$a < strlen($tmp); $a++){
+       echo $tmp{$a}, ': ', date($tmp{$a}, 1043324459)."\n";
+}
+
+putenv ("TZ=MET");
+
+for($a = 0;$a < strlen($tmp); $a++){
+       echo $tmp{$a}, ': ', date($tmp{$a}, 1043324459)."\n";
+}
+?>
+--EXPECT--
+c: 2003-01-23T12:20:59+00:00
+r: Thu, 23 Jan 2003 12:20:59 +0000
+c: 2003-01-23T13:20:59+01:00
+r: Thu, 23 Jan 2003 13:20:59 +0100