ILIAS  release_8 Revision v8.23
ChangeTimezone.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
26 use DateTimeZone;
29 
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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A transformation is a function from one datatype to another.
Change the timezone (and only the timezone) of php&#39;s WITHOUT changing the date-value.