ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
9 
15 {
17 
21  private $timezone;
22 
27  public function __construct(string $timezone)
28  {
29  if (!in_array($timezone, timezone_identifiers_list())) {
30  throw new \InvalidArgumentException("$timezone is not a valid timezone identifier", 1);
31  }
32  $this->timezone = new \DateTimeZone($timezone);
33  }
34 
38  public function transform($from)
39  {
40  if (!$from instanceof \DateTimeImmutable) {
41  throw new \InvalidArgumentException("$from is not a DateTimeImmutable-object", 1);
42  }
43 
44  $ts = $from->format('Y-m-d H:i:s');
45  $to = new \DateTimeImmutable($ts, $this->timezone);
46  return $to;
47  }
48 
52  public function __invoke($from)
53  {
54  return $this->transform($from);
55  }
56 }
__invoke($from)
Transformations should be callable.This MUST do the same as transform.
transform($from)
Perform the transformation.Please use this for transformations. It&#39;s more performant than calling inv...
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.