ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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)
 @inheritDoc More...
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 transform ($from)
 Perform the transformation. More...
 
 applyTo (Result $result)
 Perform the transformation and reify possible failures. More...
 
 __invoke ($from)
 Transformations should be callable. More...
 

Private Attributes

DateTimeZone $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 34 of file ChangeTimezone.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 41 of file ChangeTimezone.php.

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 }

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

Member Function Documentation

◆ transform()

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

@inheritDoc

Implements ILIAS\Refinery\Transformation.

Definition at line 52 of file ChangeTimezone.php.

52 : 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 }

Field Documentation

◆ $timezone

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

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