ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ILIAS\Refinery\DateTime\ChangeTimezone Class Reference

Change the timezone (and only the timezone) of php's \DateTimeImmutable 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

InvalidArgumentException if the argument could not be transformed

Parameters
mixed$from
Returns
mixed
More...
 
 __invoke ($from)
 Transformations should be callable.This MUST do the same as transform.
Exceptions

InvalidArgumentException if the argument could not be transformed

Parameters
mixed$from
Returns
mixed
More...
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 transform ($from)
 Perform the transformation. More...
 
 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 \DateTimeImmutable WITHOUT changing the date-value.

This will effectively be another point in time and space.

Definition at line 14 of file ChangeTimezone.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 27 of file ChangeTimezone.php.

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 }

References ILIAS\Refinery\DateTime\ChangeTimezone\$timezone.

Member Function Documentation

◆ __invoke()

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

Transformations should be callable.This MUST do the same as transform.

Exceptions

InvalidArgumentException if the argument could not be transformed

Parameters
mixed$from
Returns
mixed

Implements ILIAS\Refinery\Transformation.

Definition at line 52 of file ChangeTimezone.php.

53 {
54 return $this->transform($from);
55 }
transform($from)
Perform the transformation.Please use this for transformations. It's more performant than calling inv...

References ILIAS\Refinery\DateTime\ChangeTimezone\transform().

+ Here is the call graph for this function:

◆ transform()

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

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

Exceptions

InvalidArgumentException if the argument could not be transformed

Parameters
mixed$from
Returns
mixed

Implements ILIAS\Refinery\Transformation.

Definition at line 38 of file ChangeTimezone.php.

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 }

Referenced by ILIAS\Refinery\DateTime\ChangeTimezone\__invoke().

+ Here is the caller graph for this function:

Field Documentation

◆ $timezone

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

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