-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeUnit.php
More file actions
73 lines (64 loc) · 1.75 KB
/
Copy pathTimeUnit.php
File metadata and controls
73 lines (64 loc) · 1.75 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
namespace Andante\Measurement\Unit\Time;
use Andante\Measurement\Contract\DimensionInterface;
use Andante\Measurement\Contract\UnitInterface;
use Andante\Measurement\Dimension\Time;
use Andante\Measurement\Unit\SymbolNotation;
use Andante\Measurement\Unit\UnitSystem;
/**
* Time units.
*
* The SI base unit of time is the second (s).
* Time units span from nanoseconds to weeks and beyond.
*/
enum TimeUnit implements UnitInterface
{
// SI prefixed units
case Nanosecond;
case Microsecond;
case Millisecond;
case Second;
// Derived time units
case Minute;
case Hour;
case Day;
case Week;
public function symbol(SymbolNotation $notation = SymbolNotation::Default): string
{
return match ($this) {
self::Nanosecond => 'ns',
self::Microsecond => match ($notation) {
SymbolNotation::ASCII => 'us',
default => 'μs',
},
self::Millisecond => 'ms',
self::Second => 's',
self::Minute => 'min',
self::Hour => 'h',
self::Day => 'd',
self::Week => 'wk',
};
}
public function name(): string
{
return match ($this) {
self::Nanosecond => 'nanosecond',
self::Microsecond => 'microsecond',
self::Millisecond => 'millisecond',
self::Second => 'second',
self::Minute => 'minute',
self::Hour => 'hour',
self::Day => 'day',
self::Week => 'week',
};
}
public function dimension(): DimensionInterface
{
return Time::instance();
}
public function system(): UnitSystem
{
return UnitSystem::SI;
}
}