|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Palmtree\Chrono; |
|
4
|
|
|
|
|
5
|
|
|
use Palmtree\Chrono\Option\TimePeriods; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @method self add(int $value, string $period) |
|
9
|
|
|
* @method self subtract(int $value, string $period) |
|
10
|
|
|
*/ |
|
11
|
|
|
class Time extends DateTime |
|
12
|
|
|
{ |
|
13
|
|
|
public function setTime(int $hour, int $minute, int $second = 0, int $microseconds = 0): self |
|
14
|
|
|
{ |
|
15
|
|
|
$this->dateTime->setTime($hour, $minute, $second, $microseconds); |
|
16
|
|
|
|
|
17
|
|
|
return $this; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function setHour(int $hour): self |
|
21
|
|
|
{ |
|
22
|
|
|
return $this->setTime($hour, $this->dateTime->format('i'), $this->dateTime->format('s'), $this->dateTime->format('u')); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function setMinute(int $minute): self |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->setTime($this->dateTime->format('H'), $minute, $this->dateTime->format('s'), $this->dateTime->format('u')); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function setSecond(int $second): self |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->setTime($this->dateTime->format('H'), $this->dateTime->format('i'), $second, $this->dateTime->format('u')); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function setMicroseconds(int $microseconds): self |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->setTime($this->dateTime->format('H'), $this->dateTime->format('i'), $this->dateTime->format('s'), $microseconds); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
5 |
|
protected function getFormatFromTimePrecision(?string $precision): string |
|
41
|
|
|
{ |
|
42
|
5 |
|
return TimePeriods::getDateFormat($precision ?? TimePeriods::SECOND); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|