com php-src: Fixed bug #74080 Add datetime constant for RFC7231: NEWS ext/date/php_date.c ext/date/tests/DateTime_verify.ph pt ext/date/tests/bug74080.phpt

[email protected] (Joe Watkins)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    618d97962a8ac59d981c8307cc704790f46090c8
Author:    Craig Duncan <[email protected]>         Sat, 1 Apr 2017 17:56:31 +0100
Committer: Joe Watkins <[email protected]>      Mon, 17 Apr 2017 08:08:54 +0100
Parents:   7dc6b04f453d0111447a3bcd1f3e88a5c32c2a22
Branches:  PHP-7.0 PHP-7.1 master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=618d97962a8ac59d981c8307cc704790f46090c8

Log:
Fixed bug #74080 Add datetime constant for RFC7231

Bugs:
https://bugs.php.net/74080

Changed paths:
  M  NEWS
  M  ext/date/php_date.c
  M  ext/date/tests/DateTime_verify.phpt
  A  ext/date/tests/bug74080.phpt


Diff:
diff --git a/NEWS b/NEWS
index 59420cc..074a30a 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ PHP                                                                        NEWS
 - Date:
   . Fixed bug #74404 (Wrong reflection on DateTimeZone::getTransitions).
     (krakjoe)
+  . Fixed bug #74080 (add constant for RFC7231 format datetime). (duncan3dc)
 
 - DOM:
   . Fixed bug #74416 (Wrong reflection on DOMNode::cloneNode).
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 9435d6b..7383682 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -765,6 +765,11 @@ PHP_RSHUTDOWN_FUNCTION(date)
 #define DATE_FORMAT_RFC1123  "D, d M Y H:i:s O"
 
 /*
+ * RFC7231, Section 7.1.1: http://tools.ietf.org/html/rfc7231
+ */
+#define DATE_FORMAT_RFC7231  "D, d M Y H:i:s \\G\\M\\T"
+
+/*
  * 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)
@@ -857,6 +862,7 @@ PHP_MINIT_FUNCTION(date)
 	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_RFC7231", DATE_FORMAT_RFC7231, CONST_CS | CONST_PERSISTENT);
 	REGISTER_STRING_CONSTANT("DATE_RFC2822", DATE_FORMAT_RFC2822, CONST_CS | CONST_PERSISTENT);
 	REGISTER_STRING_CONSTANT("DATE_RFC3339", DATE_FORMAT_RFC3339, CONST_CS | CONST_PERSISTENT);
 	REGISTER_STRING_CONSTANT("DATE_RFC3339_EXTENDED", DATE_FORMAT_RFC3339_EXTENDED, CONST_CS | CONST_PERSISTENT);
@@ -2050,6 +2056,7 @@ static void date_register_classes(void) /* {{{ */
 	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("RFC7231",          DATE_FORMAT_RFC7231);
 	REGISTER_DATE_CLASS_CONST_STRING("RFC2822",          DATE_FORMAT_RFC2822);
 	REGISTER_DATE_CLASS_CONST_STRING("RFC3339",          DATE_FORMAT_RFC3339);
 	REGISTER_DATE_CLASS_CONST_STRING("RFC3339_EXTENDED", DATE_FORMAT_RFC3339_EXTENDED);
diff --git a/ext/date/tests/DateTime_verify.phpt b/ext/date/tests/DateTime_verify.phpt
index 3376896..bb3ed99 100644
--- a/ext/date/tests/DateTime_verify.phpt
+++ b/ext/date/tests/DateTime_verify.phpt
@@ -156,7 +156,7 @@ array(18) {
   }
 }
 ..and get names of all its class constants
-array(12) {
+array(13) {
   ["ATOM"]=>
   string(13) "Y-m-d\TH:i:sP"
   ["COOKIE"]=>
@@ -171,6 +171,8 @@ array(12) {
   string(16) "D, d M y H:i:s O"
   ["RFC1123"]=>
   string(16) "D, d M Y H:i:s O"
+  ["RFC7231"]=>
+  string(21) "D, d M Y H:i:s \G\M\T"
   ["RFC2822"]=>
   string(16) "D, d M Y H:i:s O"
   ["RFC3339"]=>
diff --git a/ext/date/tests/bug74080.phpt b/ext/date/tests/bug74080.phpt
new file mode 100644
index 0000000..3c881ed
--- /dev/null
+++ b/ext/date/tests/bug74080.phpt
@@ -0,0 +1,11 @@
+--TEST--
+Bug #74080 Provide an RFC7231 date time format
+--FILE--
+<?php
+
+$date = mktime(17, 52, 13, 4, 30, 2016);
+var_dump(date(\DateTime::RFC7231, $date));
+
+?>
+--EXPECTF--
+string(29) "Sat, 30 Apr 2016 17:52:13 GMT"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.