1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace loophp\nanobench\Time; |
11
|
|
|
|
12
|
|
|
final class Time extends AbstractTime |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var float |
16
|
|
|
*/ |
17
|
|
|
protected $time; |
18
|
|
|
|
19
|
23 |
|
public function __construct(float $time, string $unit = TimeUnit::SECOND) |
20
|
|
|
{ |
21
|
23 |
|
$this->time = $time; |
22
|
23 |
|
$this->unit = $unit; |
23
|
23 |
|
} |
24
|
|
|
|
25
|
2 |
|
public function as(string $timeUnit): float |
26
|
|
|
{ |
27
|
2 |
|
return $this->convertTo($this->time, $timeUnit); |
28
|
|
|
} |
29
|
|
|
|
30
|
2 |
|
public function asDay(): float |
31
|
|
|
{ |
32
|
2 |
|
return $this->convertTo($this->time, TimeUnit::DAY); |
33
|
|
|
} |
34
|
|
|
|
35
|
2 |
|
public function asHour(): float |
36
|
|
|
{ |
37
|
2 |
|
return $this->convertTo($this->time, TimeUnit::HOUR); |
38
|
|
|
} |
39
|
|
|
|
40
|
2 |
|
public function asMicrosecond(): float |
41
|
|
|
{ |
42
|
2 |
|
return $this->convertTo($this->time, TimeUnit::MICROSECOND); |
43
|
|
|
} |
44
|
|
|
|
45
|
13 |
|
public function asMillisecond(): float |
46
|
|
|
{ |
47
|
13 |
|
return $this->convertTo($this->time, TimeUnit::MILLISECOND); |
48
|
|
|
} |
49
|
|
|
|
50
|
2 |
|
public function asMinute(): float |
51
|
|
|
{ |
52
|
2 |
|
return $this->convertTo($this->time, TimeUnit::MINUTE); |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
public function asNanosecond(): float |
56
|
|
|
{ |
57
|
2 |
|
return $this->convertTo($this->time, TimeUnit::NANOSECOND); |
58
|
|
|
} |
59
|
|
|
|
60
|
12 |
|
public function asSecond(): float |
61
|
|
|
{ |
62
|
12 |
|
return $this->convertTo($this->time, TimeUnit::SECOND); |
63
|
|
|
} |
64
|
|
|
|
65
|
2 |
|
public function asWeek(): float |
66
|
|
|
{ |
67
|
2 |
|
return $this->convertTo($this->time, TimeUnit::WEEK); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|