ILIAS
release_8 Revision v8.23
◀ ilDoc Overview
ChangeTimezone.php
Go to the documentation of this file.
1
<?php
2
3
declare(strict_types=1);
4
21
namespace
ILIAS\Refinery\DateTime
;
22
23
use
ILIAS\Refinery\DeriveApplyToFromTransform
;
24
use
ILIAS\Refinery\Transformation
;
25
use
ILIAS\Refinery\DeriveInvokeFromTransform
;
26
use
DateTimeZone
;
27
use
InvalidArgumentException
;
28
use
DateTimeImmutable
;
29
34
class
ChangeTimezone
implements
Transformation
35
{
36
use
DeriveApplyToFromTransform
;
37
use
DeriveInvokeFromTransform
;
38
39
private
DateTimeZone
$timezone
;
40
41
public
function
__construct
(
string
$timezone)
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
}
48
52
public
function
transform
($from):
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
}
62
}
DateTimeImmutable
DateTimeZone
ILIAS\Refinery\DateTime\ChangeTimezone\__construct
__construct(string $timezone)
Definition:
ChangeTimezone.php:41
Transformation
ILIAS\Refinery\DeriveApplyToFromTransform
trait DeriveApplyToFromTransform
Definition:
DeriveApplyToFromTransform.php:29
ILIAS\Refinery\DateTime\ChangeTimezone\transform
transform($from)
Definition:
ChangeTimezone.php:52
ILIAS\Refinery\DateTime\ChangeTimezone\$timezone
DateTimeZone $timezone
Definition:
ChangeTimezone.php:39
ILIAS\Refinery\DeriveInvokeFromTransform
trait DeriveInvokeFromTransform
Definition:
DeriveInvokeFromTransform.php:27
ILIAS\Refinery\DateTime
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition:
ChangeTimezone.php:21
ILIAS\Refinery\Transformation
A transformation is a function from one datatype to another.
Definition:
Transformation.php:34
InvalidArgumentException
ILIAS\Refinery\DateTime\ChangeTimezone
Change the timezone (and only the timezone) of php's WITHOUT changing the date-value.
Definition:
ChangeTimezone.php:34
src
Refinery
DateTime
ChangeTimezone.php
Generated on Wed Sep 3 2025 22:02:55 for ILIAS by
1.8.13 (using
Doxyfile
)