From: Derick Rethans Date: Tue, 30 May 2006 13:08:00 +0000 (+0000) Subject: - Fixed bug #37616: DATE_RFC822 does not product RFC 822 dates. (Patch by X-Git-Tag: BEFORE_NEW_OUTPUT_API~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d31d2e896ad5cf3dde8b66a32e35325c1c12a07;p=php - Fixed bug #37616: DATE_RFC822 does not product RFC 822 dates. (Patch by Hannes Magnusson) --- diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 24282546d8..ba95844d71 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -243,11 +243,87 @@ PHP_RSHUTDOWN_FUNCTION(date) #define DATE_TIMEZONEDB php_date_global_timezone_db ? php_date_global_timezone_db : timelib_builtin_db() +/* + * RFC822, Section 5.1: http://www.ietf.org/rfc/rfc822.txt + * date-time = [ day "," ] date time ; dd mm yy hh:mm:ss zzz + * day = "Mon" / "Tue" / "Wed" / "Thu" / "Fri" / "Sat" / "Sun" + * date = 1*2DIGIT month 2DIGIT ; day month year e.g. 20 Jun 82 + * month = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" / "Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec" + * time = hour zone ; ANSI and Military + * hour = 2DIGIT ":" 2DIGIT [":" 2DIGIT] ; 00:00:00 - 23:59:59 + * zone = "UT" / "GMT" / "EST" / "EDT" / "CST" / "CDT" / "MST" / "MDT" / "PST" / "PDT" / 1ALPHA / ( ("+" / "-") 4DIGIT ) + */ +#define DATE_FORMAT_RFC822 "D, d M y H:i:s O" + +/* + * RFC850, Section 2.1.4: http://www.ietf.org/rfc/rfc850.txt + * Format must be acceptable both to the ARPANET and to the getdate routine. + * One format that is acceptable to both is Weekday, DD-Mon-YY HH:MM:SS TIMEZONE + * TIMEZONE can be any timezone name (3 or more letters) + */ +#define DATE_FORMAT_RFC850 "l, d-M-y H:i:s T" + +/* + * RFC1036, Section 2.1.2: http://www.ietf.org/rfc/rfc1036.txt + * Its format must be acceptable both in RFC-822 and to the getdate(3) + * Wdy, DD Mon YY HH:MM:SS TIMEZONE + * There is no hope of having a complete list of timezones. Universal + * Time (GMT), the North American timezones (PST, PDT, MST, MDT, CST, + * CDT, EST, EDT) and the +/-hhmm offset specifed in RFC-822 should be supported. + */ +#define DATE_FORMAT_RFC1036 "D, d M y H:i:s O" + +/* + * RFC1123, Section 5.2.14: http://www.ietf.org/rfc/rfc1123.txt + * RFC-822 Date and Time Specification: RFC-822 Section 5 + * The syntax for the date is hereby changed to: date = 1*2DIGIT month 2*4DIGIT + */ +#define DATE_FORMAT_RFC1123 "D, d M Y H:i:s O" + +/* + * RFC2822, Section 3.3: http://www.ietf.org/rfc/rfc2822.txt + * FWS = ([*WSP CRLF] 1*WSP) / ; Folding white space + * CFWS = *([FWS] comment) (([FWS] comment) / FWS) + * + * date-time = [ day-of-week "," ] date FWS time [CFWS] + * day-of-week = ([FWS] day-name) + * day-name = "Mon" / "Tue" / "Wed" / "Thu" / "Fri" / "Sat" / "Sun" + * date = day month year + * year = 4*DIGIT + * month = (FWS month-name FWS) + * month-name = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" / "Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec" + * day = ([FWS] 1*2DIGIT) + * time = time-of-day FWS zone + * time-of-day = hour ":" minute [ ":" second ] + * hour = 2DIGIT + * minute = 2DIGIT + * second = 2DIGIT + * zone = (( "+" / "-" ) 4DIGIT) + */ +#define DATE_FORMAT_RFC2822 "D, d M Y H:i:s O" +/* + * RFC3339, Section 5.6: http://www.ietf.org/rfc/rfc3339.txt + * date-fullyear = 4DIGIT + * date-month = 2DIGIT ; 01-12 + * date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on month/year + * + * time-hour = 2DIGIT ; 00-23 + * time-minute = 2DIGIT ; 00-59 + * time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second rules + * + * time-secfrac = "." 1*DIGIT + * time-numoffset = ("+" / "-") time-hour ":" time-minute + * time-offset = "Z" / time-numoffset + * + * partial-time = time-hour ":" time-minute ":" time-second [time-secfrac] + * full-date = date-fullyear "-" date-month "-" date-mday + * full-time = partial-time time-offset + * + * date-time = full-date "T" full-time + */ #define DATE_FORMAT_RFC3339 "Y-m-d\\TH:i:sP" + #define DATE_FORMAT_ISO8601 "Y-m-d\\TH:i:sO" -#define DATE_FORMAT_RFC1036 "l, d-M-y H:i:s T" -#define DATE_FORMAT_RFC1123 "D, d M Y H:i:s T" -#define DATE_FORMAT_RFC2822 "D, d M Y H:i:s O" #define DATE_TZ_ERRMSG \ "It is not safe to rely on the system's timezone settings. Please use " \ @@ -272,8 +348,8 @@ PHP_MINIT_FUNCTION(date) REGISTER_STRING_CONSTANT("DATE_ATOM", DATE_FORMAT_RFC3339, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("DATE_COOKIE", DATE_FORMAT_RFC1123, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("DATE_ISO8601", DATE_FORMAT_ISO8601, CONST_CS | CONST_PERSISTENT); - REGISTER_STRING_CONSTANT("DATE_RFC822", DATE_FORMAT_RFC1123, CONST_CS | CONST_PERSISTENT); - REGISTER_STRING_CONSTANT("DATE_RFC850", DATE_FORMAT_RFC1036, CONST_CS | CONST_PERSISTENT); + REGISTER_STRING_CONSTANT("DATE_RFC822", DATE_FORMAT_RFC822, CONST_CS | CONST_PERSISTENT); + REGISTER_STRING_CONSTANT("DATE_RFC850", DATE_FORMAT_RFC850, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("DATE_RFC1036", DATE_FORMAT_RFC1036, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("DATE_RFC1123", DATE_FORMAT_RFC1123, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("DATE_RFC2822", DATE_FORMAT_RFC2822, CONST_CS | CONST_PERSISTENT); @@ -1339,14 +1415,14 @@ static void date_register_classes(TSRMLS_D) REGISTER_DATE_CLASS_CONST_STRING("ATOM", DATE_FORMAT_RFC3339); REGISTER_DATE_CLASS_CONST_STRING("COOKIE", DATE_FORMAT_RFC1123); REGISTER_DATE_CLASS_CONST_STRING("ISO8601", DATE_FORMAT_ISO8601); - REGISTER_DATE_CLASS_CONST_STRING("RFC822", DATE_FORMAT_RFC1123); - REGISTER_DATE_CLASS_CONST_STRING("RFC850", DATE_FORMAT_RFC1036); + REGISTER_DATE_CLASS_CONST_STRING("RFC822", DATE_FORMAT_RFC822); + REGISTER_DATE_CLASS_CONST_STRING("RFC850", DATE_FORMAT_RFC850); REGISTER_DATE_CLASS_CONST_STRING("RFC1036", DATE_FORMAT_RFC1036); REGISTER_DATE_CLASS_CONST_STRING("RFC1123", DATE_FORMAT_RFC1123); REGISTER_DATE_CLASS_CONST_STRING("RFC2822", DATE_FORMAT_RFC2822); REGISTER_DATE_CLASS_CONST_STRING("RFC3339", DATE_FORMAT_RFC3339); REGISTER_DATE_CLASS_CONST_STRING("RSS", DATE_FORMAT_RFC1123); - REGISTER_DATE_CLASS_CONST_STRING("W3C", DATE_FORMAT_ISO8601); + REGISTER_DATE_CLASS_CONST_STRING("W3C", DATE_FORMAT_RFC3339); INIT_CLASS_ENTRY(ce_timezone, "timezone", date_funcs_timezone); diff --git a/ext/date/tests/bug37616.phpt b/ext/date/tests/bug37616.phpt new file mode 100644 index 0000000000..eac0f0ccbb --- /dev/null +++ b/ext/date/tests/bug37616.phpt @@ -0,0 +1,3 @@ + +--TEST--
Bug #37616 (DATE_RFC822 does not product RFC 822 dates)
--FILE--
<?php
    date_default_timezone_set
("Europe/Oslo");
    
var_dump(date(DATE_RFC822strtotime("1 Jul 06 14:27:30 +0200")));
?>
--EXPECT--
string(29) "Sat, 01 Jul 06 14:27:30 +0200"
+
\ No newline at end of file diff --git a/ext/date/tests/date_constants.phpt b/ext/date/tests/date_constants.phpt new file mode 100644 index 0000000000..058d0cffd0 --- /dev/null +++ b/ext/date/tests/date_constants.phpt @@ -0,0 +1,3 @@ + +--TEST--
Date constants
--FILE--
<?php
    date_default_timezone_set
("Europe/Oslo");
    
$constants = array(
        
DATE_ATOM,
        
DATE_COOKIE,
        
DATE_ISO8601,
        
DATE_RFC822,
        
DATE_RFC850,
        
DATE_RFC1036,
        
DATE_RFC1123,
        
DATE_RFC2822,
        
DATE_RSS,
        
DATE_W3C
    
);
    
    foreach(
$constants as $const) {
        
var_dump(date($conststrtotime("1 Jul 06 14:27:30 +0200")));
        
var_dump(date($conststrtotime("2006-05-30T14:32:13+02:00")));
    }
?>
--EXPECT--
string(25) "2006-07-01T14:27:30+02:00"
string(25) "2006-05-30T14:32:13+02:00"
string(31) "Sat, 01 Jul 2006 14:27:30 +0200"
string(31) "Tue, 30 May 2006 14:32:13 +0200"
string(24) "2006-07-01T14:27:30+0200"
string(24) "2006-05-30T14:32:13+0200"
string(29) "Sat, 01 Jul 06 14:27:30 +0200"
string(29) "Tue, 30 May 06 14:32:13 +0200"
string(33) "Saturday, 01-Jul-06 14:27:30 CEST"
string(32) "Tuesday, 30-May-06 14:32:13 CEST"
string(29) "Sat, 01 Jul 06 14:27:30 +0200"
string(29) "Tue, 30 May 06 14:32:13 +0200"
string(31) "Sat, 01 Jul 2006 14:27:30 +0200"
string(31) "Tue, 30 May 2006 14:32:13 +0200"
string(31) "Sat, 01 Jul 2006 14:27:30 +0200"
string(31) "Tue, 30 May 2006 14:32:13 +0200"
string(31) "Sat, 01 Jul 2006 14:27:30 +0200"
string(31) "Tue, 30 May 2006 14:32:13 +0200"
string(25) "2006-07-01T14:27:30+02:00"
string(25) "2006-05-30T14:32:13+02:00"
+
\ No newline at end of file