-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperatureUnit.php
More file actions
66 lines (58 loc) · 1.76 KB
/
Copy pathTemperatureUnit.php
File metadata and controls
66 lines (58 loc) · 1.76 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
<?php
declare(strict_types=1);
namespace Andante\Measurement\Unit\Temperature;
use Andante\Measurement\Contract\DimensionInterface;
use Andante\Measurement\Contract\UnitInterface;
use Andante\Measurement\Dimension\Temperature;
use Andante\Measurement\Unit\SymbolNotation;
use Andante\Measurement\Unit\UnitSystem;
/**
* Temperature units.
*
* The SI base unit of temperature is the kelvin (K).
*
* Temperature conversions require affine transformations (scale + offset),
* not just multiplication:
* - Kelvin (K): base unit, factor=1, offset=0
* - Celsius (°C): K = °C + 273.15, factor=1, offset=273.15
* - Fahrenheit (°F): K = (°F + 459.67) × 5/9, factor=5/9, offset=255.372222...
*/
enum TemperatureUnit implements UnitInterface
{
case Kelvin;
case Celsius;
case Fahrenheit;
public function symbol(SymbolNotation $notation = SymbolNotation::Default): string
{
return match ($this) {
self::Kelvin => 'K',
self::Celsius => match ($notation) {
SymbolNotation::ASCII => 'C',
default => '°C',
},
self::Fahrenheit => match ($notation) {
SymbolNotation::ASCII => 'F',
default => '°F',
},
};
}
public function name(): string
{
return match ($this) {
self::Kelvin => 'kelvin',
self::Celsius => 'celsius',
self::Fahrenheit => 'fahrenheit',
};
}
public function dimension(): DimensionInterface
{
return Temperature::instance();
}
public function system(): UnitSystem
{
return match ($this) {
self::Kelvin, self::Celsius => UnitSystem::SI,
self::Fahrenheit => UnitSystem::Imperial,
};
}
}