ILIAS  trunk Revision v11.0_alpha-1846-g895b5f47236
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ChangeTimezone.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 use DateTimeZone;
29 
34 class ChangeTimezone implements Transformation
35 {
38 
40 
41  public function __construct(string $timezone)
42  {
43  if (!in_array($timezone, timezone_identifiers_list(), true)) {
44  throw new InvalidArgumentException("$timezone is not a valid timezone identifier", 1);
45  }
46  $this->timezone = new DateTimeZone($timezone);
47  }
48 
52  public function transform($from): DateTimeImmutable
53  {
54  if (!$from instanceof DateTimeImmutable) {
55  throw new InvalidArgumentException("$from is not a DateTimeImmutable-object", 1);
56  }
57 
58  $ts = $from->format('Y-m-d H:i:s');
59 
60  return new DateTimeImmutable($ts, $this->timezone);
61  }
62 }
__construct(string $timezone)
Change the timezone (and only the timezone) of php&#39;s WITHOUT changing the date-value.