From: Derick Rethans Date: Tue, 16 Dec 2003 22:52:48 +0000 (+0000) Subject: - Added 'c' modifier to date() which returns the date in ISO 8601 format. X-Git-Tag: php-5.0.0b3RC1~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7fd0bdf0333a8eb9e668b33855f6f436382bbce;p=php - Added 'c' modifier to date() which returns the date in ISO 8601 format. --- diff --git a/NEWS b/NEWS index 0eafc4590b..782dfd8fcf 100644 --- 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 diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c index f9f7c2a9e6..47e14eddad 100644 --- a/ext/standard/datetime.c +++ b/ext/standard/datetime.c @@ -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 index 0000000000..87cae0b310 --- /dev/null +++ b/ext/standard/tests/time/date.phpt @@ -0,0 +1,22 @@ +--TEST-- +date() function +--FILE-- + +--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