-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DateTime.php
48 lines (39 loc) · 943 Bytes
/
DateTime.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace SonsOfPHP\Component\Clock;
use Stringable;
/**
* @author Joshua Estes <[email protected]>
*/
final readonly class DateTime implements DateTimeInterface, Stringable
{
public function __construct(private DateInterface $date, private TimeInterface $time, private ZoneInterface $zone) {}
/**
* @see self::toString()
*/
public function __toString(): string
{
return $this->toString();
}
public function toString(): string
{
return sprintf(
'%sT%s%s',
$this->getDate(),
$this->getTime(),
$this->getZone()->getOffset()
);
}
public function getDate(): DateInterface
{
return $this->date;
}
public function getTime(): TimeInterface
{
return $this->time;
}
public function getZone(): ZoneInterface
{
return $this->zone;
}
}