Total Complexity | 7 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
18 | class Time |
||
19 | { |
||
20 | private $datetime; |
||
21 | |||
22 | public function __construct(string $time) |
||
23 | { |
||
24 | $tempdate = new DateTimeImmutable($time); |
||
25 | $this->datetime = new DateTimeImmutable( |
||
26 | '1970-01-01 ' . $tempdate->format('H:i:s.u'), |
||
27 | new DateTimeZone('UTC') |
||
28 | ); |
||
29 | } |
||
30 | |||
31 | public function add(TimeInterval $interval) : Time |
||
32 | { |
||
33 | $self = clone($this); |
||
34 | $self->datetime = $this->datetime->add($interval->getDateTimeInterval()); |
||
35 | |||
36 | return $self; |
||
37 | } |
||
38 | |||
39 | public function sub(TimeInterval $interval) : Time |
||
40 | { |
||
41 | $self = clone($this); |
||
42 | $self->datetime = $this->datetime->sub($interval->getDateTimeInterval()); |
||
43 | |||
44 | return $self; |
||
45 | } |
||
46 | |||
47 | public function format(string $format) : string |
||
48 | { |
||
49 | $format = $this->sanitizeFormatString($format); |
||
50 | |||
51 | return $this->datetime->format($format); |
||
52 | } |
||
53 | |||
54 | public function diff(Time $time) : TimeInterval |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | public static function fromDateTimeInterface(DateTimeInterface $datetime) |
||
62 | { |
||
63 | return new self($datetime->format('H:i:s.u')); |
||
64 | } |
||
65 | |||
66 | private function sanitizeFormatString(string $format) : string |
||
69 | } |
||
70 | } |
||
71 |