ILIAS  release_7 Revision v7.30-3-g800a261c036
ILIAS\Refinery\DateTime\ChangeTimezone Class Reference

Change the timezone (and only the timezone) of php's WITHOUT changing the date-value. More...

+ Inheritance diagram for ILIAS\Refinery\DateTime\ChangeTimezone:
+ Collaboration diagram for ILIAS\Refinery\DateTime\ChangeTimezone:

Public Member Functions

 __construct (string $timezone)
 
 transform ($from)
 Perform the transformation.Please use this for transformations. It's more performant than calling invoke.
Exceptions
More...
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 applyTo (Result $data)
 Perform the transformation and reify possible failures. More...
 
 __invoke ($from)
 Transformations should be callable. More...
 

Private Attributes

 $timezone
 

Detailed Description

Change the timezone (and only the timezone) of php's WITHOUT changing the date-value.

This will effectively be another point in time and space.

Definition at line 15 of file ChangeTimezone.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Refinery\DateTime\ChangeTimezone::__construct ( string  $timezone)
Parameters
string$timezone
Factory$factory

Definition at line 29 of file ChangeTimezone.php.

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  }

Member Function Documentation

◆ transform()

ILIAS\Refinery\DateTime\ChangeTimezone::transform (   $from)

Perform the transformation.Please use this for transformations. It's more performant than calling invoke.

Exceptions

Implements ILIAS\Refinery\Transformation.

Definition at line 40 of file ChangeTimezone.php.

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  }

Field Documentation

◆ $timezone

ILIAS\Refinery\DateTime\ChangeTimezone::$timezone
private

Definition at line 23 of file ChangeTimezone.php.


The documentation for this class was generated from the following file: