xref: /PHP-8.0/ext/date/tests/date_parse_001.phpt (revision 5dafd7b4)
1--TEST--
2Test basic date_parse()
3--FILE--
4<?php
5    date_default_timezone_set('UTC');
6    var_dump(date_parse("2006-12-12 10:00:00.5"));
7    var_dump(date_parse("2006-12-12"));
8    var_dump(date_parse("2006-12--12"));
9    var_dump(date_parse("2006-02-30"));
10    var_dump(date_parse("2006-03-04"));
11    var_dump(date_parse("2006-03"));
12    var_dump(date_parse("03-03"));
13    var_dump(date_parse("0-0"));
14    var_dump(date_parse(""));
15    echo "Done\n";
16?>
17--EXPECT--
18array(12) {
19  ["year"]=>
20  int(2006)
21  ["month"]=>
22  int(12)
23  ["day"]=>
24  int(12)
25  ["hour"]=>
26  int(10)
27  ["minute"]=>
28  int(0)
29  ["second"]=>
30  int(0)
31  ["fraction"]=>
32  float(0.5)
33  ["warning_count"]=>
34  int(0)
35  ["warnings"]=>
36  array(0) {
37  }
38  ["error_count"]=>
39  int(0)
40  ["errors"]=>
41  array(0) {
42  }
43  ["is_localtime"]=>
44  bool(false)
45}
46array(12) {
47  ["year"]=>
48  int(2006)
49  ["month"]=>
50  int(12)
51  ["day"]=>
52  int(12)
53  ["hour"]=>
54  bool(false)
55  ["minute"]=>
56  bool(false)
57  ["second"]=>
58  bool(false)
59  ["fraction"]=>
60  bool(false)
61  ["warning_count"]=>
62  int(0)
63  ["warnings"]=>
64  array(0) {
65  }
66  ["error_count"]=>
67  int(0)
68  ["errors"]=>
69  array(0) {
70  }
71  ["is_localtime"]=>
72  bool(false)
73}
74array(15) {
75  ["year"]=>
76  int(2006)
77  ["month"]=>
78  int(12)
79  ["day"]=>
80  int(1)
81  ["hour"]=>
82  bool(false)
83  ["minute"]=>
84  bool(false)
85  ["second"]=>
86  bool(false)
87  ["fraction"]=>
88  bool(false)
89  ["warning_count"]=>
90  int(0)
91  ["warnings"]=>
92  array(0) {
93  }
94  ["error_count"]=>
95  int(1)
96  ["errors"]=>
97  array(1) {
98    [7]=>
99    string(20) "Unexpected character"
100  }
101  ["is_localtime"]=>
102  bool(true)
103  ["zone_type"]=>
104  int(1)
105  ["zone"]=>
106  int(-43200)
107  ["is_dst"]=>
108  bool(false)
109}
110array(12) {
111  ["year"]=>
112  int(2006)
113  ["month"]=>
114  int(2)
115  ["day"]=>
116  int(30)
117  ["hour"]=>
118  bool(false)
119  ["minute"]=>
120  bool(false)
121  ["second"]=>
122  bool(false)
123  ["fraction"]=>
124  bool(false)
125  ["warning_count"]=>
126  int(1)
127  ["warnings"]=>
128  array(1) {
129    [11]=>
130    string(27) "The parsed date was invalid"
131  }
132  ["error_count"]=>
133  int(0)
134  ["errors"]=>
135  array(0) {
136  }
137  ["is_localtime"]=>
138  bool(false)
139}
140array(12) {
141  ["year"]=>
142  int(2006)
143  ["month"]=>
144  int(3)
145  ["day"]=>
146  int(4)
147  ["hour"]=>
148  bool(false)
149  ["minute"]=>
150  bool(false)
151  ["second"]=>
152  bool(false)
153  ["fraction"]=>
154  bool(false)
155  ["warning_count"]=>
156  int(0)
157  ["warnings"]=>
158  array(0) {
159  }
160  ["error_count"]=>
161  int(0)
162  ["errors"]=>
163  array(0) {
164  }
165  ["is_localtime"]=>
166  bool(false)
167}
168array(12) {
169  ["year"]=>
170  int(2006)
171  ["month"]=>
172  int(3)
173  ["day"]=>
174  int(1)
175  ["hour"]=>
176  bool(false)
177  ["minute"]=>
178  bool(false)
179  ["second"]=>
180  bool(false)
181  ["fraction"]=>
182  bool(false)
183  ["warning_count"]=>
184  int(0)
185  ["warnings"]=>
186  array(0) {
187  }
188  ["error_count"]=>
189  int(0)
190  ["errors"]=>
191  array(0) {
192  }
193  ["is_localtime"]=>
194  bool(false)
195}
196array(15) {
197  ["year"]=>
198  bool(false)
199  ["month"]=>
200  bool(false)
201  ["day"]=>
202  bool(false)
203  ["hour"]=>
204  bool(false)
205  ["minute"]=>
206  bool(false)
207  ["second"]=>
208  bool(false)
209  ["fraction"]=>
210  bool(false)
211  ["warning_count"]=>
212  int(0)
213  ["warnings"]=>
214  array(0) {
215  }
216  ["error_count"]=>
217  int(2)
218  ["errors"]=>
219  array(2) {
220    [0]=>
221    string(20) "Unexpected character"
222    [1]=>
223    string(20) "Unexpected character"
224  }
225  ["is_localtime"]=>
226  bool(true)
227  ["zone_type"]=>
228  int(1)
229  ["zone"]=>
230  int(-10800)
231  ["is_dst"]=>
232  bool(false)
233}
234array(15) {
235  ["year"]=>
236  bool(false)
237  ["month"]=>
238  bool(false)
239  ["day"]=>
240  bool(false)
241  ["hour"]=>
242  bool(false)
243  ["minute"]=>
244  bool(false)
245  ["second"]=>
246  bool(false)
247  ["fraction"]=>
248  bool(false)
249  ["warning_count"]=>
250  int(0)
251  ["warnings"]=>
252  array(0) {
253  }
254  ["error_count"]=>
255  int(1)
256  ["errors"]=>
257  array(1) {
258    [0]=>
259    string(20) "Unexpected character"
260  }
261  ["is_localtime"]=>
262  bool(true)
263  ["zone_type"]=>
264  int(1)
265  ["zone"]=>
266  int(0)
267  ["is_dst"]=>
268  bool(false)
269}
270array(12) {
271  ["year"]=>
272  bool(false)
273  ["month"]=>
274  bool(false)
275  ["day"]=>
276  bool(false)
277  ["hour"]=>
278  bool(false)
279  ["minute"]=>
280  bool(false)
281  ["second"]=>
282  bool(false)
283  ["fraction"]=>
284  bool(false)
285  ["warning_count"]=>
286  int(0)
287  ["warnings"]=>
288  array(0) {
289  }
290  ["error_count"]=>
291  int(1)
292  ["errors"]=>
293  array(1) {
294    [0]=>
295    string(12) "Empty string"
296  }
297  ["is_localtime"]=>
298  bool(false)
299}
300Done
301