ILIAS  release_7 Revision v7.30-3-g800a261c036
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 
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 }
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.