-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTime.php
56 lines (46 loc) · 1.01 KB
/
Time.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
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace SonsOfPHP\Component\Clock;
use Stringable;
/**
* @author Joshua Estes <[email protected]>
*/
final readonly class Time implements TimeInterface, Stringable
{
public function __construct(
private int $hour,
private int $minute,
private int $second,
private int $millisecond
) {}
public function __toString(): string
{
return $this->toString();
}
public function toString(): string
{
return sprintf(
'%02d:%02d:%02d.%03d',
$this->getHour(),
$this->getMinute(),
$this->getSecond(),
$this->getMillisecond()
);
}
public function getHour(): int
{
return $this->hour;
}
public function getMinute(): int
{
return $this->minute;
}
public function getSecond(): int
{
return $this->second;
}
public function getMillisecond(): int
{
return $this->millisecond;
}
}