1--TEST--
2RFC: DateTime and Daylight Saving Time Transitions (zone type 1)
3--CREDITS--
4Daniel Convissor <danielc@php.net>
5--FILE--
6<?php
7
8date_default_timezone_set('America/New_York');
9$date_format = 'Y-m-d H:i:s e';
10$interval_format = 'P%dDT%hH';
11
12/*
13 * Forward Transitions, diff().
14 */
15
16$end   = new DateTime('2010-03-14 03:00:00 -0400');
17$start = new DateTime('2010-03-14 01:59:59 -0500');
18echo 'fd1 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
19	. ' = ' . $start->diff($end)->format('PT%hH%iM%sS') . "\n";
20
21$end   = new DateTime('2010-03-14 04:30:00 -0400');
22$start = new DateTime('2010-03-13 04:30:00 -0500');
23echo 'fd2 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
24	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
25
26$end   = new DateTime('2010-03-14 03:30:00 -0400');
27$start = new DateTime('2010-03-13 04:30:00 -0500');
28echo 'fd3 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
29	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
30
31$end   = new DateTime('2010-03-14 01:30:00 -0500');
32$start = new DateTime('2010-03-13 04:30:00 -0500');
33echo 'fd4 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
34	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
35
36$end   = new DateTime('2010-03-14 01:30:00 -0500');
37$start = new DateTime('2010-03-13 01:30:00 -0500');
38echo 'fd5 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
39	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
40
41$end   = new DateTime('2010-03-14 03:30:00 -0400');
42$start = new DateTime('2010-03-13 03:30:00 -0500');
43echo 'fd6 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
44	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
45
46$end   = new DateTime('2010-03-14 03:30:00 -0400');
47$start = new DateTime('2010-03-13 02:30:00 -0500');
48echo 'fd7 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
49	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
50
51echo "\n";
52
53/*
54 * Forward Transitions, add().
55 */
56
57$start = new DateTime('2010-03-14 01:59:59 -0500');
58$interval_spec = 'PT1S';
59$interval = new DateInterval($interval_spec);
60echo 'fa1 ' . $start->format($date_format) . " + $interval_spec = "
61	. $start->add($interval)->format($date_format) . "\n";
62
63$start = new DateTime('2010-03-13 04:30:00 -0500');
64$interval_spec = 'P1D';
65$interval = new DateInterval($interval_spec);
66echo 'fa2 ' . $start->format($date_format) . " + $interval_spec = "
67	. $start->add($interval)->format($date_format) . "\n";
68
69$start = new DateTime('2010-03-13 04:30:00 -0500');
70$interval_spec = 'PT22H';
71$interval = new DateInterval($interval_spec);
72echo 'fa3 ' . $start->format($date_format) . " + $interval_spec = "
73	. $start->add($interval)->format($date_format) . "\n";
74
75$start = new DateTime('2010-03-13 04:30:00 -0500');
76$interval_spec = 'PT21H';
77$interval = new DateInterval($interval_spec);
78echo 'fa4 ' . $start->format($date_format) . " + $interval_spec = "
79	. $start->add($interval)->format($date_format) . "\n";
80
81$start = new DateTime('2010-03-13 01:30:00 -0500');
82$interval_spec = 'P1D';
83$interval = new DateInterval($interval_spec);
84echo 'fa5 ' . $start->format($date_format) . " + $interval_spec = "
85	. $start->add($interval)->format($date_format) . "\n";
86
87$start = new DateTime('2010-03-13 02:30:00 -0500');
88$interval_spec = 'P1D';
89$interval = new DateInterval($interval_spec);
90echo 'fa6 ' . $start->format($date_format) . " + $interval_spec = "
91	. $start->add($interval)->format($date_format) . "\n";
92
93echo "\n";
94
95/*
96 * Forward Transitions, sub().
97 */
98
99$end   = new DateTime('2010-03-14 03:00:00 -0400');
100$interval_spec = 'PT1S';
101$interval = new DateInterval($interval_spec);
102echo 'fs1 ' . $end->format($date_format) . " - $interval_spec = "
103	. $end->sub($interval)->format($date_format) . "\n";
104
105$end   = new DateTime('2010-03-14 04:30:00 -0400');
106$interval_spec = 'P1D';
107$interval = new DateInterval($interval_spec);
108echo 'fs2 ' . $end->format($date_format) . " - $interval_spec = "
109	. $end->sub($interval)->format($date_format) . "\n";
110
111$end   = new DateTime('2010-03-14 03:30:00 -0400');
112$interval_spec = 'PT22H';
113$interval = new DateInterval($interval_spec);
114echo 'fs3 ' . $end->format($date_format) . " - $interval_spec = "
115	. $end->sub($interval)->format($date_format) . "\n";
116
117$end   = new DateTime('2010-03-14 01:30:00 -0500');
118$interval_spec = 'PT21H';
119$interval = new DateInterval($interval_spec);
120echo 'fs4 ' . $end->format($date_format) . " - $interval_spec = "
121	. $end->sub($interval)->format($date_format) . "\n";
122
123$end   = new DateTime('2010-03-14 01:30:00 -0500');
124$interval_spec = 'P1D';
125$interval = new DateInterval($interval_spec);
126echo 'fs5 ' . $end->format($date_format) . " - $interval_spec = "
127	. $end->sub($interval)->format($date_format) . "\n";
128
129$end   = new DateTime('2010-03-15 03:30:00 -0400');
130$interval_spec = 'P1D';
131$interval = new DateInterval($interval_spec);
132echo 'fs6 ' . $end->format($date_format) . " - $interval_spec = "
133	. $end->sub($interval)->format($date_format) . "\n";
134
135$end   = new DateTime('2010-03-15 02:30:00 -0400');
136$interval_spec = 'P1D';
137$interval = new DateInterval($interval_spec);
138echo 'fs7 ' . $end->format($date_format) . " - $interval_spec = "
139	. $end->sub($interval)->format($date_format) . "\n";
140
141echo "\n";
142
143/*
144 * Backward Transitions, diff().
145 */
146
147$end   = new DateTime('2010-11-07 01:00:00 -0500');
148$start = new DateTime('2010-11-07 01:59:59 -0400');
149echo 'bd1 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
150	. ' = ' . $start->diff($end)->format('PT%hH%iM%sS') . "\n";
151
152$end   = new DateTime('2010-11-07 04:30:00 -0500');
153$start = new DateTime('2010-11-06 04:30:00 -0400');
154echo 'bd2 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
155	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
156
157$end   = new DateTime('2010-11-07 03:30:00 -0500');
158$start = new DateTime('2010-11-06 04:30:00 -0400');
159echo 'bd3 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
160	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
161
162$end   = new DateTime('2010-11-07 02:30:00 -0500');
163$start = new DateTime('2010-11-06 04:30:00 -0400');
164echo 'bd4 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
165	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
166
167$end   = new DateTime('2010-11-07 01:30:00 -0500');
168$start = new DateTime('2010-11-06 04:30:00 -0400');
169echo 'bd5 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
170	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
171
172$end   = new DateTime('2010-11-07 01:30:00 -0400');
173$start = new DateTime('2010-11-06 04:30:00 -0400');
174echo 'bd6 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
175	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
176
177$end   = new DateTime('2010-11-07 01:30:00 -0400');
178$start = new DateTime('2010-11-06 01:30:00 -0400');
179echo 'bd7 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
180	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
181
182$end   = new DateTime('2010-11-07 01:30:00 -0500');
183$start = new DateTime('2010-11-06 01:30:00 -0400');
184echo 'bd8 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
185	. ' = ' . $start->diff($end)->format($interval_format) . "\n";
186
187echo "\n";
188
189/*
190 * Backward Transitions, add().
191 */
192
193$start = new DateTime('2010-11-07 01:59:59 -0400');
194$interval_spec = 'PT1S';
195$interval = new DateInterval($interval_spec);
196echo 'ba1 ' . $start->format($date_format) . " + $interval_spec = "
197	. $start->add($interval)->format($date_format) . "\n";
198
199$start = new DateTime('2010-11-06 04:30:00 -0400');
200$interval_spec = 'P1D';
201$interval = new DateInterval($interval_spec);
202echo 'ba2 ' . $start->format($date_format) . " + $interval_spec = "
203	. $start->add($interval)->format($date_format) . "\n";
204
205$start = new DateTime('2010-11-06 04:30:00 -0400');
206$interval_spec = 'PT24H';
207$interval = new DateInterval($interval_spec);
208echo 'ba3 ' . $start->format($date_format) . " + $interval_spec = "
209	. $start->add($interval)->format($date_format) . "\n";
210
211$start = new DateTime('2010-11-06 04:30:00 -0400');
212$interval_spec = 'PT23H';
213$interval = new DateInterval($interval_spec);
214echo 'ba4 ' . $start->format($date_format) . " + $interval_spec = "
215	. $start->add($interval)->format($date_format) . "\n";
216
217$start = new DateTime('2010-11-06 04:30:00 -0400');
218$interval_spec = 'PT22H';
219$interval = new DateInterval($interval_spec);
220echo 'ba5 ' . $start->format($date_format) . " + $interval_spec = "
221	. $start->add($interval)->format($date_format) . "\n";
222
223$start = new DateTime('2010-11-06 04:30:00 -0400');
224$interval_spec = 'PT21H';
225$interval = new DateInterval($interval_spec);
226echo 'ba6 ' . $start->format($date_format) . " + $interval_spec = "
227	. $start->add($interval)->format($date_format) . "\n";
228
229$start = new DateTime('2010-11-06 01:30:00 -0400');
230$interval_spec = 'P1D';
231$interval = new DateInterval($interval_spec);
232echo 'ba7 ' . $start->format($date_format) . " + $interval_spec = "
233	. $start->add($interval)->format($date_format) . "\n";
234
235$start = new DateTime('2010-11-06 01:30:00 -0400');
236$interval_spec = 'P1DT1H';
237$interval = new DateInterval($interval_spec);
238echo 'ba8 ' . $start->format($date_format) . " + $interval_spec = "
239	. $start->add($interval)->format($date_format) . "\n";
240
241$start = new DateTime('2010-11-06 04:30:00 -0400');
242$interval_spec = 'PT25H';
243$interval = new DateInterval($interval_spec);
244echo 'ba9 ' . $start->format($date_format) . " + $interval_spec = "
245	. $start->add($interval)->format($date_format) . "\n";
246
247$start = new DateTime('2010-11-06 03:30:00 -0400');
248$interval_spec = 'P1D';
249$interval = new DateInterval($interval_spec);
250echo 'ba10 ' . $start->format($date_format) . " + $interval_spec = "
251	. $start->add($interval)->format($date_format) . "\n";
252
253$start = new DateTime('2010-11-06 02:30:00 -0400');
254$interval_spec = 'P1D';
255$interval = new DateInterval($interval_spec);
256echo 'ba11 ' . $start->format($date_format) . " + $interval_spec = "
257	. $start->add($interval)->format($date_format) . "\n";
258
259echo "\n";
260
261/*
262 * Backward Transitions, sub().
263 */
264
265$end   = new DateTime('2010-11-07 01:00:00 -0500');
266$interval_spec = 'PT1S';
267$interval = new DateInterval($interval_spec);
268echo 'bs1 ' . $end->format($date_format) . " - $interval_spec = "
269	. $end->sub($interval)->format($date_format) . "\n";
270
271$end   = new DateTime('2010-11-07 04:30:00 -0500');
272$interval_spec = 'P1D';
273$interval = new DateInterval($interval_spec);
274echo 'bs2 ' . $end->format($date_format) . " - $interval_spec = "
275	. $end->sub($interval)->format($date_format) . "\n";
276
277$end   = new DateTime('2010-11-07 03:30:00 -0500');
278$interval_spec = 'PT24H';
279$interval = new DateInterval($interval_spec);
280echo 'bs3 ' . $end->format($date_format) . " - $interval_spec = "
281	. $end->sub($interval)->format($date_format) . "\n";
282
283$end   = new DateTime('2010-11-07 02:30:00 -0500');
284$interval_spec = 'PT23H';
285$interval = new DateInterval($interval_spec);
286echo 'bs4 ' . $end->format($date_format) . " - $interval_spec = "
287	. $end->sub($interval)->format($date_format) . "\n";
288
289$end   = new DateTime('2010-11-07 01:30:00 -0500');
290$interval_spec = 'PT22H';
291$interval = new DateInterval($interval_spec);
292echo 'bs5 ' . $end->format($date_format) . " - $interval_spec = "
293	. $end->sub($interval)->format($date_format) . "\n";
294
295$end   = new DateTime('2010-11-07 01:30:00 -0400');
296$interval_spec = 'PT21H';
297$interval = new DateInterval($interval_spec);
298echo 'bs6 ' . $end->format($date_format) . " - $interval_spec = "
299	. $end->sub($interval)->format($date_format) . "\n";
300
301$end   = new DateTime('2010-11-07 01:30:00 -0400');
302$interval_spec = 'P1D';
303$interval = new DateInterval($interval_spec);
304echo 'bs7 ' . $end->format($date_format) . " - $interval_spec = "
305	. $end->sub($interval)->format($date_format) . "\n";
306
307$end   = new DateTime('2010-11-07 01:30:00 -0500');
308$interval_spec = 'P1DT1H';
309$interval = new DateInterval($interval_spec);
310echo 'bs8 ' . $end->format($date_format) . " - $interval_spec = "
311	. $end->sub($interval)->format($date_format) . "\n";
312
313$end   = new DateTime('2010-11-07 03:30:00 -0500');
314$interval_spec = 'P1D';
315$interval = new DateInterval($interval_spec);
316echo 'bs9 ' . $end->format($date_format) . " - $interval_spec = "
317	. $end->sub($interval)->format($date_format) . "\n";
318
319$end   = new DateTime('2010-11-07 02:30:00 -0500');
320$interval_spec = 'P1D';
321$interval = new DateInterval($interval_spec);
322echo 'bs10 ' . $end->format($date_format) . " - $interval_spec = "
323	. $end->sub($interval)->format($date_format) . "\n";
324
325?>
326--EXPECT--
327fd1 2010-03-14 03:00:00 -04:00 - 2010-03-14 01:59:59 -05:00 = PT0H0M1S
328fd2 2010-03-14 04:30:00 -04:00 - 2010-03-13 04:30:00 -05:00 = P0DT23H
329fd3 2010-03-14 03:30:00 -04:00 - 2010-03-13 04:30:00 -05:00 = P0DT22H
330fd4 2010-03-14 01:30:00 -05:00 - 2010-03-13 04:30:00 -05:00 = P0DT21H
331fd5 2010-03-14 01:30:00 -05:00 - 2010-03-13 01:30:00 -05:00 = P1DT0H
332fd6 2010-03-14 03:30:00 -04:00 - 2010-03-13 03:30:00 -05:00 = P0DT23H
333fd7 2010-03-14 03:30:00 -04:00 - 2010-03-13 02:30:00 -05:00 = P1DT0H
334
335fa1 2010-03-14 01:59:59 -05:00 + PT1S = 2010-03-14 02:00:00 -05:00
336fa2 2010-03-13 04:30:00 -05:00 + P1D = 2010-03-14 04:30:00 -05:00
337fa3 2010-03-13 04:30:00 -05:00 + PT22H = 2010-03-14 02:30:00 -05:00
338fa4 2010-03-13 04:30:00 -05:00 + PT21H = 2010-03-14 01:30:00 -05:00
339fa5 2010-03-13 01:30:00 -05:00 + P1D = 2010-03-14 01:30:00 -05:00
340fa6 2010-03-13 02:30:00 -05:00 + P1D = 2010-03-14 02:30:00 -05:00
341
342fs1 2010-03-14 03:00:00 -04:00 - PT1S = 2010-03-14 02:59:59 -04:00
343fs2 2010-03-14 04:30:00 -04:00 - P1D = 2010-03-13 04:30:00 -04:00
344fs3 2010-03-14 03:30:00 -04:00 - PT22H = 2010-03-13 05:30:00 -04:00
345fs4 2010-03-14 01:30:00 -05:00 - PT21H = 2010-03-13 04:30:00 -05:00
346fs5 2010-03-14 01:30:00 -05:00 - P1D = 2010-03-13 01:30:00 -05:00
347fs6 2010-03-15 03:30:00 -04:00 - P1D = 2010-03-14 03:30:00 -04:00
348fs7 2010-03-15 02:30:00 -04:00 - P1D = 2010-03-14 02:30:00 -04:00
349
350bd1 2010-11-07 01:00:00 -05:00 - 2010-11-07 01:59:59 -04:00 = PT0H0M1S
351bd2 2010-11-07 04:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P1DT1H
352bd3 2010-11-07 03:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P1DT0H
353bd4 2010-11-07 02:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P0DT23H
354bd5 2010-11-07 01:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P0DT22H
355bd6 2010-11-07 01:30:00 -04:00 - 2010-11-06 04:30:00 -04:00 = P0DT21H
356bd7 2010-11-07 01:30:00 -04:00 - 2010-11-06 01:30:00 -04:00 = P1DT0H
357bd8 2010-11-07 01:30:00 -05:00 - 2010-11-06 01:30:00 -04:00 = P1DT1H
358
359ba1 2010-11-07 01:59:59 -04:00 + PT1S = 2010-11-07 02:00:00 -04:00
360ba2 2010-11-06 04:30:00 -04:00 + P1D = 2010-11-07 04:30:00 -04:00
361ba3 2010-11-06 04:30:00 -04:00 + PT24H = 2010-11-07 04:30:00 -04:00
362ba4 2010-11-06 04:30:00 -04:00 + PT23H = 2010-11-07 03:30:00 -04:00
363ba5 2010-11-06 04:30:00 -04:00 + PT22H = 2010-11-07 02:30:00 -04:00
364ba6 2010-11-06 04:30:00 -04:00 + PT21H = 2010-11-07 01:30:00 -04:00
365ba7 2010-11-06 01:30:00 -04:00 + P1D = 2010-11-07 01:30:00 -04:00
366ba8 2010-11-06 01:30:00 -04:00 + P1DT1H = 2010-11-07 02:30:00 -04:00
367ba9 2010-11-06 04:30:00 -04:00 + PT25H = 2010-11-07 05:30:00 -04:00
368ba10 2010-11-06 03:30:00 -04:00 + P1D = 2010-11-07 03:30:00 -04:00
369ba11 2010-11-06 02:30:00 -04:00 + P1D = 2010-11-07 02:30:00 -04:00
370
371bs1 2010-11-07 01:00:00 -05:00 - PT1S = 2010-11-07 00:59:59 -05:00
372bs2 2010-11-07 04:30:00 -05:00 - P1D = 2010-11-06 04:30:00 -05:00
373bs3 2010-11-07 03:30:00 -05:00 - PT24H = 2010-11-06 03:30:00 -05:00
374bs4 2010-11-07 02:30:00 -05:00 - PT23H = 2010-11-06 03:30:00 -05:00
375bs5 2010-11-07 01:30:00 -05:00 - PT22H = 2010-11-06 03:30:00 -05:00
376bs6 2010-11-07 01:30:00 -04:00 - PT21H = 2010-11-06 04:30:00 -04:00
377bs7 2010-11-07 01:30:00 -04:00 - P1D = 2010-11-06 01:30:00 -04:00
378bs8 2010-11-07 01:30:00 -05:00 - P1DT1H = 2010-11-06 00:30:00 -05:00
379bs9 2010-11-07 03:30:00 -05:00 - P1D = 2010-11-06 03:30:00 -05:00
380bs10 2010-11-07 02:30:00 -05:00 - P1D = 2010-11-06 02:30:00 -05:00
381