ILIAS  release_7 Revision v7.30-3-g800a261c036
ChangeTimezone.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
5
10
16{
19
23 private $timezone;
24
29 public function __construct(string $timezone)
30 {
31 if (!in_array($timezone, timezone_identifiers_list())) {
32 throw new \InvalidArgumentException("$timezone is not a valid timezone identifier", 1);
33 }
34 $this->timezone = new \DateTimeZone($timezone);
35 }
36
40 public function transform($from)
41 {
42 if (!$from instanceof \DateTimeImmutable) {
43 throw new \InvalidArgumentException("$from is not a DateTimeImmutable-object", 1);
44 }
45
46 $ts = $from->format('Y-m-d H:i:s');
47 $to = new \DateTimeImmutable($ts, $this->timezone);
48 return $to;
49 }
50}
An exception for terminatinating execution or to throw for unit testing.
Change the timezone (and only the timezone) of php's \DateTimeImmutable WITHOUT changing the date-val...
transform($from)
Perform the transformation.Please use this for transformations. It's more performant than calling inv...
A transformation is a function from one datatype to another.