@@ -279,6 +279,78 @@ public function testSubmitWithSecondsAndBrowserOmissionSeconds()
279
279
$ this ->assertEquals ('03:04:00 ' , $ form ->getViewData ());
280
280
}
281
281
282
+ public function testPreSetDataDifferentTimezones ()
283
+ {
284
+ var_dump (date_default_timezone_get ());
285
+
286
+ $ form = $ this ->factory ->create (static ::TESTED_TYPE , null , [
287
+ 'model_timezone ' => 'UTC ' ,
288
+ 'view_timezone ' => 'Europe/Berlin ' ,
289
+ 'input ' => 'datetime ' ,
290
+ 'with_seconds ' => true ,
291
+ 'reference_date ' => new \DateTimeImmutable ('2019-01-01 ' , new \DateTimeZone ('UTC ' )),
292
+ ]);
293
+ $ form ->setData (new \DateTime ('2022-01-01 15:09:10 ' ));
294
+
295
+ $ this ->assertSame ('15:09:10 ' , $ form ->getData ()->format ('H:i:s ' ));
296
+ $ this ->assertSame ([
297
+ 'hour ' => '16 ' ,
298
+ 'minute ' => '9 ' ,
299
+ 'second ' => '10 ' ,
300
+ ], $ form ->getViewData ());
301
+ }
302
+
303
+ public function testPreSetDataDifferentTimezonesDuringDaylightSavingTime ()
304
+ {
305
+ $ form = $ this ->factory ->create (static ::TESTED_TYPE , null , [
306
+ 'model_timezone ' => 'UTC ' ,
307
+ 'view_timezone ' => 'Europe/Berlin ' ,
308
+ 'input ' => 'datetime ' ,
309
+ 'with_seconds ' => true ,
310
+ 'reference_date ' => new \DateTimeImmutable ('2019-07-12 ' , new \DateTimeZone ('UTC ' )),
311
+ ]);
312
+ $ form ->setData (new \DateTime ('2022-04-29 15:09:10 ' ));
313
+
314
+ $ this ->assertSame ('15:09:10 ' , $ form ->getData ()->format ('H:i:s ' ));
315
+ $ this ->assertSame ([
316
+ 'hour ' => '17 ' ,
317
+ 'minute ' => '9 ' ,
318
+ 'second ' => '10 ' ,
319
+ ], $ form ->getViewData ());
320
+ }
321
+
322
+ public function testPreSetDataDifferentTimezonesUsingSingleTextWidget ()
323
+ {
324
+ $ form = $ this ->factory ->create (static ::TESTED_TYPE , null , [
325
+ 'model_timezone ' => 'UTC ' ,
326
+ 'view_timezone ' => 'Europe/Berlin ' ,
327
+
629A
'input ' => 'datetime ' ,
328
+ 'with_seconds ' => true ,
329
+ 'reference_date ' => new \DateTimeImmutable ('2019-01-01 ' , new \DateTimeZone ('UTC ' )),
330
+ 'widget ' => 'single_text ' ,
331
+ ]);
332
+ $ form ->setData (new \DateTime ('2022-01-01 15:09:10 ' ));
333
+
334
+ $ this ->assertSame ('15:09:10 ' , $ form ->getData ()->format ('H:i:s ' ));
335
+ $ this ->assertSame ('16:09:10 ' , $ form ->getViewData ());
336
+ }
337
+
338
+ public function testPreSetDataDifferentTimezonesDuringDaylightSavingTimeUsingSingleTextWidget ()
339
+ {
340
+ $ form = $ this ->factory ->create (static ::TESTED_TYPE , null , [
341
+ 'model_timezone ' => 'UTC ' ,
342
+ 'view_timezone ' => 'Europe/Berlin ' ,
343
+ 'input ' => 'datetime ' ,
344
+ 'with_seconds ' => true ,
345
+ 'reference_date ' => new \DateTimeImmutable ('2019-07-12 ' , new \DateTimeZone ('UTC ' )),
346
+ 'widget ' => 'single_text ' ,
347
+ ]);
348
+ $ form ->setData (new \DateTime ('2022-04-29 15:09:10 ' ));
349
+
350
+ $ this ->assertSame ('15:09:10 ' , $ form ->getData ()->format ('H:i:s ' ));
351
+ $ this ->assertSame ('17:09:10 ' , $ form ->getViewData ());
352
+ }
353
+
282
354
public function testSubmitDifferentTimezones ()
283
355
{
284
356
$ form = $ this ->factory ->create (static ::TESTED_TYPE , null , [
0 commit comments