19declare(strict_types=1);
23use PHPUnit\Framework\TestCase;
29 protected function setUp(): void
36 $dat =
'2019-05-26 13:15:01';
37 $origin_tz =
'Europe/Berlin';
38 $target_tz =
'Europe/London';
39 $origin =
new DateTimeImmutable($dat,
new DateTimeZone($origin_tz));
40 $expected =
new DateTimeImmutable($dat,
new DateTimeZone($target_tz));
41 $trans = $this->dt->changeTimezone($target_tz);
45 $trans->transform($origin)
51 $dat =
'2019-05-26 13:15:01';
52 $origin_tz =
'Europe/Berlin';
53 $target_tz =
'America/El_Salvador';
54 $origin =
new DateTimeImmutable($dat,
new DateTimeZone($origin_tz));
55 $trans = $this->dt->changeTimezone($target_tz);
58 date_format($trans->transform($origin),
'Y-m-d H:i:s')
64 $trans = $this->dt->changeTimezone(
'Europe/Berlin');
65 $this->expectException(InvalidArgumentException::class);
66 $trans->transform(
null);
71 $this->expectException(InvalidArgumentException::class);
72 $trans = $this->dt->changeTimezone(
'Europe/Berlin');
73 $trans->transform(
'erroneous');
78 $dat =
'2019/05/26 16:05:22';
79 $origin_tz =
'Europe/Berlin';
80 $target_tz =
'Europe/London';
81 $origin =
new DateTimeImmutable($dat,
new DateTimeZone($origin_tz));
82 $expected =
new DateTimeImmutable($dat,
new DateTimeZone($target_tz));
83 $trans = $this->dt->changeTimezone($target_tz);
84 $this->assertEquals($expected, $trans($origin));
89 $trans = $this->dt->changeTimezone(
'Europe/London');
90 $value =
'2019/05/26';
91 $origin =
new DateTimeImmutable($value);
92 $expected =
new DateTimeImmutable($value,
new DateTimeZone(
'Europe/London'));
94 $df =
new DataFactory();
95 $ok = $df->ok($origin);
97 $result = $trans->applyTo($ok);
98 $this->assertEquals($expected, $result->value());
99 $this->assertFalse($result->isError());
104 $trans = $this->dt->changeTimezone(
'Europe/London');
105 $df =
new DataFactory();
106 $ok = $df->ok(
'not_a_date');
108 $result = $trans->applyTo($ok);
109 $this->assertTrue($result->isError());