1--TEST--
2Tests for DateTimeImmutable.
3--INI--
4date.timezone=Europe/London
5--FILE--
6<?php
7$tz = new DateTimeZone("Asia/Tokyo");
8$current = "2012-12-27 16:24:08";
9
10function dump($a, $b, $c)
11{
12    echo 'orig:    ', $a->format('Y-m-d H:i:s e'), "\n";
13    echo 'copy:    ', $b->format('Y-m-d H:i:s e'), "\n";
14    echo 'changed: ', $c->format('Y-m-d H:i:s e'), "\n";
15}
16
17echo "modify():\n";
18$v = date_create_immutable($current);
19$z = $v;
20$x = $z->modify("+2 days");
21dump($v, $z, $x);
22$v = date_create($current);
23$z = $v;
24$x = $z->modify("+2 days");
25dump($v, $z, $x);
26
27echo "\nadd():\n";
28$v = date_create_immutable($current);
29$z = $v;
30$x = $z->add(new DateInterval("P2DT2S"));
31dump($v, $z, $x);
32$v = date_create($current);
33$z = $v;
34$x = $z->add(new DateInterval("P2DT2S"));
35dump($v, $z, $x);
36
37echo "\nsub():\n";
38$v = date_create_immutable($current);
39$z = $v;
40$x = $z->sub(new DateInterval("P2DT2S"));
41dump($v, $z, $x);
42$v = date_create($current);
43$z = $v;
44$x = $z->sub(new DateInterval("P2DT2S"));
45dump($v, $z, $x);
46
47echo "\nsetTimezone():\n";
48$v = date_create_immutable($current);
49$z = $v;
50$x = $z->setTimezone($tz);
51dump($v, $z, $x);
52$v = date_create($current);
53$z = $v;
54$x = $z->setTimezone($tz);
55dump($v, $z, $x);
56$v = new DateTimeImmutable($current);
57$z = $v;
58$x = $z->setTimezone($tz);
59dump($v, $z, $x);
60
61echo "\nsetTime():\n";
62$v = date_create_immutable($current);
63$z = $v;
64$x = $z->setTime(5, 7, 19);
65dump($v, $z, $x);
66$v = date_create($current);
67$z = $v;
68$x = $z->setTime(5, 7, 19);
69dump($v, $z, $x);
70
71echo "\nsetDate():\n";
72$v = date_create_immutable($current);
73$z = $v;
74$x = $z->setDate(5, 7, 19);
75dump($v, $z, $x);
76$v = date_create($current);
77$z = $v;
78$x = $z->setDate(5, 7, 19);
79dump($v, $z, $x);
80
81echo "\nsetIsoDate():\n";
82$v = date_create_immutable($current);
83$z = $v;
84$x = $z->setIsoDate(2012, 2, 6);
85dump($v, $z, $x);
86$v = date_create($current);
87$z = $v;
88$x = $z->setIsoDate(2012, 2, 6);
89dump($v, $z, $x);
90
91echo "\nsetTimestamp():\n";
92$v = date_create_immutable($current);
93$z = $v;
94$x = $z->setTimestamp(2012234222);
95dump($v, $z, $x);
96$v = date_create($current);
97$z = $v;
98$x = $z->setTimestamp(2012234222);
99dump($v, $z, $x);
100?>
101--EXPECT--
102modify():
103orig:    2012-12-27 16:24:08 Europe/London
104copy:    2012-12-27 16:24:08 Europe/London
105changed: 2012-12-29 16:24:08 Europe/London
106orig:    2012-12-29 16:24:08 Europe/London
107copy:    2012-12-29 16:24:08 Europe/London
108changed: 2012-12-29 16:24:08 Europe/London
109
110add():
111orig:    2012-12-27 16:24:08 Europe/London
112copy:    2012-12-27 16:24:08 Europe/London
113changed: 2012-12-29 16:24:10 Europe/London
114orig:    2012-12-29 16:24:10 Europe/London
115copy:    2012-12-29 16:24:10 Europe/London
116changed: 2012-12-29 16:24:10 Europe/London
117
118sub():
119orig:    2012-12-27 16:24:08 Europe/London
120copy:    2012-12-27 16:24:08 Europe/London
121changed: 2012-12-25 16:24:06 Europe/London
122orig:    2012-12-25 16:24:06 Europe/London
123copy:    2012-12-25 16:24:06 Europe/London
124changed: 2012-12-25 16:24:06 Europe/London
125
126setTimezone():
127orig:    2012-12-27 16:24:08 Europe/London
128copy:    2012-12-27 16:24:08 Europe/London
129changed: 2012-12-28 01:24:08 Asia/Tokyo
130orig:    2012-12-28 01:24:08 Asia/Tokyo
131copy:    2012-12-28 01:24:08 Asia/Tokyo
132changed: 2012-12-28 01:24:08 Asia/Tokyo
133orig:    2012-12-27 16:24:08 Europe/London
134copy:    2012-12-27 16:24:08 Europe/London
135changed: 2012-12-28 01:24:08 Asia/Tokyo
136
137setTime():
138orig:    2012-12-27 16:24:08 Europe/London
139copy:    2012-12-27 16:24:08 Europe/London
140changed: 2012-12-27 05:07:19 Europe/London
141orig:    2012-12-27 05:07:19 Europe/London
142copy:    2012-12-27 05:07:19 Europe/London
143changed: 2012-12-27 05:07:19 Europe/London
144
145setDate():
146orig:    2012-12-27 16:24:08 Europe/London
147copy:    2012-12-27 16:24:08 Europe/London
148changed: 0005-07-19 16:24:08 Europe/London
149orig:    0005-07-19 16:24:08 Europe/London
150copy:    0005-07-19 16:24:08 Europe/London
151changed: 0005-07-19 16:24:08 Europe/London
152
153setIsoDate():
154orig:    2012-12-27 16:24:08 Europe/London
155copy:    2012-12-27 16:24:08 Europe/London
156changed: 2012-01-14 16:24:08 Europe/London
157orig:    2012-01-14 16:24:08 Europe/London
158copy:    2012-01-14 16:24:08 Europe/London
159changed: 2012-01-14 16:24:08 Europe/London
160
161setTimestamp():
162orig:    2012-12-27 16:24:08 Europe/London
163copy:    2012-12-27 16:24:08 Europe/London
164changed: 2033-10-06 18:57:02 Europe/London
165orig:    2033-10-06 18:57:02 Europe/London
166copy:    2033-10-06 18:57:02 Europe/London
167changed: 2033-10-06 18:57:02 Europe/London
168