1--TEST--
2Bug #68549 (setting timestamp around a DST transition)
3--CREDITS--
4Roel Harbers <roel.harbers@on2it.net>
5--FILE--
6<?php
7$timezonesWithTimestamps = [
8    'America/Los_Angeles' => [
9        // LANG=en_US TZ="America/Los_Angeles" date --date=@<...>
10        // forward:
11        1615687199, // Sat Mar 13 17:59:59 PST 2021 (Sun Mar 14 01:59:59 UTC 2021)
12        1615687200, // Sat Mar 13 18:00:00 PST 2021 (Sun Mar 14 02:00:00 UTC 2021)
13        1615687201, // Sat Mar 13 18:00:01 PST 2021 (Sun Mar 14 02:00:01 UTC 2021)
14        1615690799, // Sat Mar 13 18:59:59 PST 2021 (Sun Mar 14 02:59:59 UTC 2021)
15        1615690800, // Sat Mar 13 19:00:00 PST 2021 (Sun Mar 14 03:00:00 UTC 2021)
16        1615690801, // Sat Mar 13 19:00:01 PST 2021 (Sun Mar 14 03:00:01 UTC 2021)
17        1615708799, // Sun Mar 13 23:59:59 PST 2021
18        1615708800, // Sun Mar 14 00:00:00 PST 2021
19        1615708801, // Sun Mar 14 00:00:01 PST 2021
20        1615712399, // Sun Mar 14 00:59:59 PST 2021
21        1615712400, // Sun Mar 14 01:00:00 PST 2021
22        1615712401, // Sun Mar 14 01:00:01 PST 2021
23        1615715999, // Sun Mar 14 01:59:59 PST 2021
24        1615716000, // Sun Mar 14 03:00:00 PDT 2021
25        1615716001, // Sun Mar 14 03:00:01 PDT 2021
26        1615719599, // Sun Mar 14 03:59:59 PDT 2021
27        1615719600, // Sun Mar 14 04:00:00 PDT 2021
28        1615719601, // Sun Mar 14 04:00:01 PDT 2021
29        // backward:
30        1636246799, // Sat Nov  6 17:59:59 PDT 2021 (Sun Nov  7 00:59:59 UTC 2021)
31        1636246800, // Sat Nov  6 18:00:00 PDT 2021 (Sun Nov  7 01:00:00 UTC 2021)
32        1636246801, // Sat Nov  6 18:00:01 PDT 2021 (Sun Nov  7 01:00:01 UTC 2021)
33        1636250399, // Sat Nov  6 18:59:59 PDT 2021 (Sun Nov  7 01:59:59 UTC 2021)
34        1636250400, // Sat Nov  6 19:00:00 PDT 2021 (Sun Nov  7 02:00:00 UTC 2021)
35        1636250401, // Sat Nov  6 19:00:01 PDT 2021 (Sun Nov  7 02:00:01 UTC 2021)
36        1636268399, // Sat Nov  6 23:59:59 PDT 2021
37        1636268400, // Sun Nov  7 00:00:00 PDT 2021
38        1636268401, // Sun Nov  7 00:00:01 PDT 2021
39        1636271999, // Sun Nov  7 00:59:59 PDT 2021
40        1636272000, // Sun Nov  7 01:00:00 PDT 2021
41        1636272001, // Sun Nov  7 01:00:01 PDT 2021
42        1636275599, // Sun Nov  7 01:59:59 PDT 2021
43        1636275600, // Sun Nov  7 01:00:00 PST 2021
44        1636275601, // Sun Nov  7 01:00:01 PST 2021
45        1636279199, // Sun Nov  7 01:59:59 PST 2021
46        1636279200, // Sun Nov  7 02:00:00 PST 2021
47        1636279201, // Sun Nov  7 02:00:01 PST 2021
48    ],
49    'Atlantic/Azores' => [
50        // LANG=en_US TZ="Atlantic/Azores" date --date=@<...>
51        // forward:
52        1616889599, // Sat Mar 27 22:59:59 AZOT 2021 (Sat Mar 27 23:59:59 UTC 2021)
53        1616889600, // Sat Mar 27 23:00:00 AZOT 2021 (Sun Mar 28 00:00:00 UTC 2021)
54        1616889601, // Sat Mar 27 23:00:01 AZOT 2021 (Sun Mar 28 00:00:01 UTC 2021)
55        1616893199, // Sat Mar 27 23:59:59 AZOT 2021 (Sun Mar 28 00:59:59 UTC 2021)
56        1616893200, // Sun Mar 28 01:00:00 AZOST 2021 (Sun Mar 28 01:00:00 UTC 2021)
57        1616893201, // Sun Mar 28 01:00:01 AZOST 2021 (Sun Mar 28 01:00:01 UTC 2021)
58        1616896799, // Sun Mar 28 01:59:59 AZOST 2021
59        1616896800, // Sun Mar 28 02:00:00 AZOST 2021
60        1616896801, // Sun Mar 28 02:00:01 AZOST 2021
61        // backward:
62        1635638399, // Sat Oct 30 23:59:59 AZOST 2021 (Sat Oct 30 23:59:59 UTC 2021)
63        1635638400, // Sun Oct 31 00:00:00 AZOST 2021 (Sun Oct 31 00:00:00 UTC 2021)
64        1635638401, // Sun Oct 31 00:00:01 AZOST 2021 (Sun Oct 31 00:00:01 UTC 2021)
65        1635641999, // Sun Oct 31 00:59:59 AZOST 2021 (Sun Oct 31 00:59:59 UTC 2021)
66        1635642000, // Sun Oct 31 00:00:00 AZOT 2021 (Sun Oct 31 01:00:00 UTC 2021)
67        1635642001, // Sun Oct 31 00:00:01 AZOT 2021 (Sun Oct 31 01:00:01 UTC 2021)
68        1635645599, // Sun Oct 31 00:59:59 AZOT 2021
69        1635645600, // Sun Oct 31 01:00:00 AZOT 2021
70        1635645601, // Sun Oct 31 01:00:01 AZOT 2021
71    ],
72    'Europe/London' => [
73        // LANG=en_US TZ="Europe/London" date --date=@<...>
74        // forward:
75        1616889599, // Sat Mar 27 23:59:59 GMT 2021
76        1616889600, // Sun Mar 28 00:00:00 GMT 2021
77        1616889601, // Sun Mar 28 00:00:01 GMT 2021
78        1616893199, // Sun Mar 28 00:59:59 GMT 2021 (Sun Mar 28 00:59:59 UTC 2021)
79        1616893200, // Sun Mar 28 02:00:00 BST 2021 (Sun Mar 28 01:00:00 UTC 2021)
80        1616893201, // Sun Mar 28 02:00:01 BST 2021 (Sun Mar 28 01:00:01 UTC 2021)
81        1616896799, // Sun Mar 28 02:59:59 BST 2021 (Sun Mar 28 01:59:59 UTC 2021)
82        1616896800, // Sun Mar 28 03:00:00 BST 2021 (Sun Mar 28 02:00:00 UTC 2021)
83        1616896801, // Sun Mar 28 03:00:01 BST 2021 (Sun Mar 28 02:00:01 UTC 2021)
84        // backward:
85        1635638399, // Sun Oct 31 00:59:59 BST 2021
86        1635638400, // Sun Oct 31 01:00:00 BST 2021
87        1635638401, // Sun Oct 31 01:00:01 BST 2021
88        1635641999, // Sun Oct 31 01:59:59 BST 2021 (Sun Oct 31 00:59:59 UTC 2021)
89        1635642000, // Sun Oct 31 01:00:00 GMT 2021 (Sun Oct 31 01:00:00 UTC 2021)
90        1635642001, // Sun Oct 31 01:00:01 GMT 2021 (Sun Oct 31 01:00:01 UTC 2021)
91        1635645599, // Sun Oct 31 01:59:59 GMT 2021 (Sun Oct 31 01:59:59 UTC 2021)
92        1635645600, // Sun Oct 31 02:00:00 GMT 2021 (Sun Oct 31 02:00:00 UTC 2021)
93        1635645601, // Sun Oct 31 02:00:01 GMT 2021 (Sun Oct 31 02:00:01 UTC 2021)
94    ],
95    'Europe/Amsterdam' => [
96        // LANG=en_US TZ="Europe/Amsterdam" date --date=@<...>
97        // forward:
98        1616885999, // Sat Mar 27 23:59:59 CET 2021
99        1616886000, // Sun Mar 28 00:00:00 CET 2021
100        1616886001, // Sun Mar 28 00:00:01 CET 2021
101        1616889599, // Sun Mar 28 00:59:59 CET 2021
102        1616889600, // Sun Mar 28 01:00:00 CET 2021
103        1616889601, // Sun Mar 28 01:00:01 CET 2021
104        1616893199, // Sun Mar 28 01:59:59 CET 2021
105        1616893200, // Sun Mar 28 03:00:00 CEST 2021
106        1616893201, // Sun Mar 28 03:00:01 CEST 2021
107        1616896799, // Sun Mar 28 03:59:59 CEST 2021 (Sun Mar 28 01:59:59 UTC 2021)
108        1616896800, // Sun Mar 28 04:00:00 CEST 2021 (Sun Mar 28 02:00:00 UTC 2021)
109        1616896801, // Sun Mar 28 04:00:01 CEST 2021 (Sun Mar 28 02:00:01 UTC 2021)
110        1616900399, // Sun Mar 28 04:59:59 CEST 2021 (Sun Mar 28 02:59:59 UTC 2021)
111        1616900400, // Sun Mar 28 05:00:00 CEST 2021 (Sun Mar 28 03:00:00 UTC 2021)
112        1616900401, // Sun Mar 28 05:00:01 CEST 2021 (Sun Mar 28 03:00:01 UTC 2021)
113        // backward:
114        1635631199, // Sat Oct 30 23:59:59 CEST 2021
115        1635631200, // Sun Oct 31 00:00:00 CEST 2021
116        1635631201, // Sun Oct 31 00:00:01 CEST 2021
117        1635638399, // Sun Oct 31 01:59:59 CEST 2021
118        1635638400, // Sun Oct 31 02:00:00 CEST 2021
119        1635638401, // Sun Oct 31 02:00:01 CEST 2021
120        1635641999, // Sun Oct 31 02:59:59 CEST 2021
121        1635642000, // Sun Oct 31 02:00:00 CET 2021
122        1635642001, // Sun Oct 31 02:00:01 CET 2021
123        1635645599, // Sun Oct 31 02:59:59 CET 2021 (Sun Oct 31 01:59:59 UTC 2021)
124        1635645600, // Sun Oct 31 03:00:00 CET 2021 (Sun Oct 31 02:00:00 UTC 2021)
125        1635645601, // Sun Oct 31 03:00:01 CET 2021 (Sun Oct 31 02:00:01 UTC 2021)
126        1635649199, // Sun Oct 31 03:59:59 CET 2021 (Sun Oct 31 02:59:59 UTC 2021)
127        1635649200, // Sun Oct 31 04:00:00 CET 2021 (Sun Oct 31 03:00:00 UTC 2021)
128        1635649201, // Sun Oct 31 04:00:01 CET 2021 (Sun Oct 31 03:00:01 UTC 2021)
129    ],
130];
131foreach ($timezonesWithTimestamps as $timezone => $timestamps) {
132    foreach ($timestamps as $timestamp) {
133        $tz = new DateTimeZone($timezone);
134        $dt = new DateTime('now', $tz);
135        $dt->setTimestamp($timestamp);
136        printf("%s %d -> %d %s\n", $timezone, $timestamp, $dt->getTimestamp(), $dt->format(DateTimeInterface::ISO8601));
137    }
138}
139?>
140--EXPECT--
141America/Los_Angeles 1615687199 -> 1615687199 2021-03-13T17:59:59-0800
142America/Los_Angeles 1615687200 -> 1615687200 2021-03-13T18:00:00-0800
143America/Los_Angeles 1615687201 -> 1615687201 2021-03-13T18:00:01-0800
144America/Los_Angeles 1615690799 -> 1615690799 2021-03-13T18:59:59-0800
145America/Los_Angeles 1615690800 -> 1615690800 2021-03-13T19:00:00-0800
146America/Los_Angeles 1615690801 -> 1615690801 2021-03-13T19:00:01-0800
147America/Los_Angeles 1615708799 -> 1615708799 2021-03-13T23:59:59-0800
148America/Los_Angeles 1615708800 -> 1615708800 2021-03-14T00:00:00-0800
149America/Los_Angeles 1615708801 -> 1615708801 2021-03-14T00:00:01-0800
150America/Los_Angeles 1615712399 -> 1615712399 2021-03-14T00:59:59-0800
151America/Los_Angeles 1615712400 -> 1615712400 2021-03-14T01:00:00-0800
152America/Los_Angeles 1615712401 -> 1615712401 2021-03-14T01:00:01-0800
153America/Los_Angeles 1615715999 -> 1615715999 2021-03-14T01:59:59-0800
154America/Los_Angeles 1615716000 -> 1615716000 2021-03-14T03:00:00-0700
155America/Los_Angeles 1615716001 -> 1615716001 2021-03-14T03:00:01-0700
156America/Los_Angeles 1615719599 -> 1615719599 2021-03-14T03:59:59-0700
157America/Los_Angeles 1615719600 -> 1615719600 2021-03-14T04:00:00-0700
158America/Los_Angeles 1615719601 -> 1615719601 2021-03-14T04:00:01-0700
159America/Los_Angeles 1636246799 -> 1636246799 2021-11-06T17:59:59-0700
160America/Los_Angeles 1636246800 -> 1636246800 2021-11-06T18:00:00-0700
161America/Los_Angeles 1636246801 -> 1636246801 2021-11-06T18:00:01-0700
162America/Los_Angeles 1636250399 -> 1636250399 2021-11-06T18:59:59-0700
163America/Los_Angeles 1636250400 -> 1636250400 2021-11-06T19:00:00-0700
164America/Los_Angeles 1636250401 -> 1636250401 2021-11-06T19:00:01-0700
165America/Los_Angeles 1636268399 -> 1636268399 2021-11-06T23:59:59-0700
166America/Los_Angeles 1636268400 -> 1636268400 2021-11-07T00:00:00-0700
167America/Los_Angeles 1636268401 -> 1636268401 2021-11-07T00:00:01-0700
168America/Los_Angeles 1636271999 -> 1636271999 2021-11-07T00:59:59-0700
169America/Los_Angeles 1636272000 -> 1636272000 2021-11-07T01:00:00-0700
170America/Los_Angeles 1636272001 -> 1636272001 2021-11-07T01:00:01-0700
171America/Los_Angeles 1636275599 -> 1636275599 2021-11-07T01:59:59-0700
172America/Los_Angeles 1636275600 -> 1636275600 2021-11-07T01:00:00-0800
173America/Los_Angeles 1636275601 -> 1636275601 2021-11-07T01:00:01-0800
174America/Los_Angeles 1636279199 -> 1636279199 2021-11-07T01:59:59-0800
175America/Los_Angeles 1636279200 -> 1636279200 2021-11-07T02:00:00-0800
176America/Los_Angeles 1636279201 -> 1636279201 2021-11-07T02:00:01-0800
177Atlantic/Azores 1616889599 -> 1616889599 2021-03-27T22:59:59-0100
178Atlantic/Azores 1616889600 -> 1616889600 2021-03-27T23:00:00-0100
179Atlantic/Azores 1616889601 -> 1616889601 2021-03-27T23:00:01-0100
180Atlantic/Azores 1616893199 -> 1616893199 2021-03-27T23:59:59-0100
181Atlantic/Azores 1616893200 -> 1616893200 2021-03-28T01:00:00+0000
182Atlantic/Azores 1616893201 -> 1616893201 2021-03-28T01:00:01+0000
183Atlantic/Azores 1616896799 -> 1616896799 2021-03-28T01:59:59+0000
184Atlantic/Azores 1616896800 -> 1616896800 2021-03-28T02:00:00+0000
185Atlantic/Azores 1616896801 -> 1616896801 2021-03-28T02:00:01+0000
186Atlantic/Azores 1635638399 -> 1635638399 2021-10-30T23:59:59+0000
187Atlantic/Azores 1635638400 -> 1635638400 2021-10-31T00:00:00+0000
188Atlantic/Azores 1635638401 -> 1635638401 2021-10-31T00:00:01+0000
189Atlantic/Azores 1635641999 -> 1635641999 2021-10-31T00:59:59+0000
190Atlantic/Azores 1635642000 -> 1635642000 2021-10-31T00:00:00-0100
191Atlantic/Azores 1635642001 -> 1635642001 2021-10-31T00:00:01-0100
192Atlantic/Azores 1635645599 -> 1635645599 2021-10-31T00:59:59-0100
193Atlantic/Azores 1635645600 -> 1635645600 2021-10-31T01:00:00-0100
194Atlantic/Azores 1635645601 -> 1635645601 2021-10-31T01:00:01-0100
195Europe/London 1616889599 -> 1616889599 2021-03-27T23:59:59+0000
196Europe/London 1616889600 -> 1616889600 2021-03-28T00:00:00+0000
197Europe/London 1616889601 -> 1616889601 2021-03-28T00:00:01+0000
198Europe/London 1616893199 -> 1616893199 2021-03-28T00:59:59+0000
199Europe/London 1616893200 -> 1616893200 2021-03-28T02:00:00+0100
200Europe/London 1616893201 -> 1616893201 2021-03-28T02:00:01+0100
201Europe/London 1616896799 -> 1616896799 2021-03-28T02:59:59+0100
202Europe/London 1616896800 -> 1616896800 2021-03-28T03:00:00+0100
203Europe/London 1616896801 -> 1616896801 2021-03-28T03:00:01+0100
204Europe/London 1635638399 -> 1635638399 2021-10-31T00:59:59+0100
205Europe/London 1635638400 -> 1635638400 2021-10-31T01:00:00+0100
206Europe/London 1635638401 -> 1635638401 2021-10-31T01:00:01+0100
207Europe/London 1635641999 -> 1635641999 2021-10-31T01:59:59+0100
208Europe/London 1635642000 -> 1635642000 2021-10-31T01:00:00+0000
209Europe/London 1635642001 -> 1635642001 2021-10-31T01:00:01+0000
210Europe/London 1635645599 -> 1635645599 2021-10-31T01:59:59+0000
211Europe/London 1635645600 -> 1635645600 2021-10-31T02:00:00+0000
212Europe/London 1635645601 -> 1635645601 2021-10-31T02:00:01+0000
213Europe/Amsterdam 1616885999 -> 1616885999 2021-03-27T23:59:59+0100
214Europe/Amsterdam 1616886000 -> 1616886000 2021-03-28T00:00:00+0100
215Europe/Amsterdam 1616886001 -> 1616886001 2021-03-28T00:00:01+0100
216Europe/Amsterdam 1616889599 -> 1616889599 2021-03-28T00:59:59+0100
217Europe/Amsterdam 1616889600 -> 1616889600 2021-03-28T01:00:00+0100
218Europe/Amsterdam 1616889601 -> 1616889601 2021-03-28T01:00:01+0100
219Europe/Amsterdam 1616893199 -> 1616893199 2021-03-28T01:59:59+0100
220Europe/Amsterdam 1616893200 -> 1616893200 2021-03-28T03:00:00+0200
221Europe/Amsterdam 1616893201 -> 1616893201 2021-03-28T03:00:01+0200
222Europe/Amsterdam 1616896799 -> 1616896799 2021-03-28T03:59:59+0200
223Europe/Amsterdam 1616896800 -> 1616896800 2021-03-28T04:00:00+0200
224Europe/Amsterdam 1616896801 -> 1616896801 2021-03-28T04:00:01+0200
225Europe/Amsterdam 1616900399 -> 1616900399 2021-03-28T04:59:59+0200
226Europe/Amsterdam 1616900400 -> 1616900400 2021-03-28T05:00:00+0200
227Europe/Amsterdam 1616900401 -> 1616900401 2021-03-28T05:00:01+0200
228Europe/Amsterdam 1635631199 -> 1635631199 2021-10-30T23:59:59+0200
229Europe/Amsterdam 1635631200 -> 1635631200 2021-10-31T00:00:00+0200
230Europe/Amsterdam 1635631201 -> 1635631201 2021-10-31T00:00:01+0200
231Europe/Amsterdam 1635638399 -> 1635638399 2021-10-31T01:59:59+0200
232Europe/Amsterdam 1635638400 -> 1635638400 2021-10-31T02:00:00+0200
233Europe/Amsterdam 1635638401 -> 1635638401 2021-10-31T02:00:01+0200
234Europe/Amsterdam 1635641999 -> 1635641999 2021-10-31T02:59:59+0200
235Europe/Amsterdam 1635642000 -> 1635642000 2021-10-31T02:00:00+0100
236Europe/Amsterdam 1635642001 -> 1635642001 2021-10-31T02:00:01+0100
237Europe/Amsterdam 1635645599 -> 1635645599 2021-10-31T02:59:59+0100
238Europe/Amsterdam 1635645600 -> 1635645600 2021-10-31T03:00:00+0100
239Europe/Amsterdam 1635645601 -> 1635645601 2021-10-31T03:00:01+0100
240Europe/Amsterdam 1635649199 -> 1635649199 2021-10-31T03:59:59+0100
241Europe/Amsterdam 1635649200 -> 1635649200 2021-10-31T04:00:00+0100
242Europe/Amsterdam 1635649201 -> 1635649201 2021-10-31T04:00:01+0100
243