1--TEST--
2date_create_from_format() and date_parse_from_format().
3--FILE--
4<?php
5date_default_timezone_set('Europe/Oslo');
6$formats = [
7    DATE_ATOM, DATE_COOKIE, DATE_ISO8601, DATE_ISO8601_EXPANDED, DATE_RFC822,
8    DATE_RFC850, DATE_RFC1036, DATE_RFC1123, DATE_RFC2822, DATE_RFC3339,
9    DATE_RFC3339_EXTENDED, DATE_RSS, DATE_W3C
10];
11
12foreach( $formats as $format )
13{
14    $date = new DateTime( "2008-07-08T22:14:12+02:00" );
15    $formatted = $date->format( $format ) ;
16    $date2 = date_create_from_format( $format, $formatted );
17    var_dump( $format, $formatted, $date2 );
18    echo "\n";
19    if ( $date2 === false )
20    {
21        var_dump(date_parse_from_format( $format, $formatted ) );
22    }
23}
24?>
25--EXPECT--
26string(13) "Y-m-d\TH:i:sP"
27string(25) "2008-07-08T22:14:12+02:00"
28object(DateTime)#2 (3) {
29  ["date"]=>
30  string(26) "2008-07-08 22:14:12.000000"
31  ["timezone_type"]=>
32  int(1)
33  ["timezone"]=>
34  string(6) "+02:00"
35}
36
37string(16) "l, d-M-Y H:i:s T"
38string(38) "Tuesday, 08-Jul-2008 22:14:12 GMT+0200"
39object(DateTime)#1 (3) {
40  ["date"]=>
41  string(26) "2008-07-08 22:14:12.000000"
42  ["timezone_type"]=>
43  int(1)
44  ["timezone"]=>
45  string(6) "+02:00"
46}
47
48string(13) "Y-m-d\TH:i:sO"
49string(24) "2008-07-08T22:14:12+0200"
50object(DateTime)#3 (3) {
51  ["date"]=>
52  string(26) "2008-07-08 22:14:12.000000"
53  ["timezone_type"]=>
54  int(1)
55  ["timezone"]=>
56  string(6) "+02:00"
57}
58
59string(13) "X-m-d\TH:i:sP"
60string(26) "+2008-07-08T22:14:12+02:00"
61object(DateTime)#2 (3) {
62  ["date"]=>
63  string(26) "2008-07-08 22:14:12.000000"
64  ["timezone_type"]=>
65  int(1)
66  ["timezone"]=>
67  string(6) "+02:00"
68}
69
70string(16) "D, d M y H:i:s O"
71string(29) "Tue, 08 Jul 08 22:14:12 +0200"
72object(DateTime)#1 (3) {
73  ["date"]=>
74  string(26) "2008-07-08 22:14:12.000000"
75  ["timezone_type"]=>
76  int(1)
77  ["timezone"]=>
78  string(6) "+02:00"
79}
80
81string(16) "l, d-M-y H:i:s T"
82string(36) "Tuesday, 08-Jul-08 22:14:12 GMT+0200"
83object(DateTime)#3 (3) {
84  ["date"]=>
85  string(26) "2008-07-08 22:14:12.000000"
86  ["timezone_type"]=>
87  int(1)
88  ["timezone"]=>
89  string(6) "+02:00"
90}
91
92string(16) "D, d M y H:i:s O"
93string(29) "Tue, 08 Jul 08 22:14:12 +0200"
94object(DateTime)#2 (3) {
95  ["date"]=>
96  string(26) "2008-07-08 22:14:12.000000"
97  ["timezone_type"]=>
98  int(1)
99  ["timezone"]=>
100  string(6) "+02:00"
101}
102
103string(16) "D, d M Y H:i:s O"
104string(31) "Tue, 08 Jul 2008 22:14:12 +0200"
105object(DateTime)#1 (3) {
106  ["date"]=>
107  string(26) "2008-07-08 22:14:12.000000"
108  ["timezone_type"]=>
109  int(1)
110  ["timezone"]=>
111  string(6) "+02:00"
112}
113
114string(16) "D, d M Y H:i:s O"
115string(31) "Tue, 08 Jul 2008 22:14:12 +0200"
116object(DateTime)#3 (3) {
117  ["date"]=>
118  string(26) "2008-07-08 22:14:12.000000"
119  ["timezone_type"]=>
120  int(1)
121  ["timezone"]=>
122  string(6) "+02:00"
123}
124
125string(13) "Y-m-d\TH:i:sP"
126string(25) "2008-07-08T22:14:12+02:00"
127object(DateTime)#2 (3) {
128  ["date"]=>
129  string(26) "2008-07-08 22:14:12.000000"
130  ["timezone_type"]=>
131  int(1)
132  ["timezone"]=>
133  string(6) "+02:00"
134}
135
136string(15) "Y-m-d\TH:i:s.vP"
137string(29) "2008-07-08T22:14:12.000+02:00"
138object(DateTime)#1 (3) {
139  ["date"]=>
140  string(26) "2008-07-08 22:14:12.000000"
141  ["timezone_type"]=>
142  int(1)
143  ["timezone"]=>
144  string(6) "+02:00"
145}
146
147string(16) "D, d M Y H:i:s O"
148string(31) "Tue, 08 Jul 2008 22:14:12 +0200"
149object(DateTime)#3 (3) {
150  ["date"]=>
151  string(26) "2008-07-08 22:14:12.000000"
152  ["timezone_type"]=>
153  int(1)
154  ["timezone"]=>
155  string(6) "+02:00"
156}
157
158string(13) "Y-m-d\TH:i:sP"
159string(25) "2008-07-08T22:14:12+02:00"
160object(DateTime)#2 (3) {
161  ["date"]=>
162  string(26) "2008-07-08 22:14:12.000000"
163  ["timezone_type"]=>
164  int(1)
165  ["timezone"]=>
166  string(6) "+02:00"
167}
168