-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemperature.go
68 lines (56 loc) · 1.75 KB
/
temperature.go
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
// SPDX-FileCopyrightText: 2023 Winni Neessen <wn@neessen.dev>
//
// SPDX-License-Identifier: MIT
package meteologix
import (
"fmt"
"math"
"time"
)
// Temperature is a type wrapper of an WeatherData for holding temperature values in WeatherData
type Temperature WeatherData
// IsAvailable returns true if an Temperature value was available at time of query
func (t Temperature) IsAvailable() bool {
return !t.notAvailable
}
// DateTime returns the time at which the temperature data was generated or fetched
func (t Temperature) DateTime() time.Time {
return t.dateTime
}
// Value returns the float64 value of an Temperature
//
// If the Temperature is not available in the WeatherData, Value will return math.NaN instead.
func (t Temperature) Value() float64 {
if t.notAvailable {
return math.NaN()
}
return t.floatVal
}
// Source returns the Source of an Temperature
//
// If the Source is not available it will return SourceUnknown
func (t Temperature) Source() Source {
return t.source
}
// String satisfies the fmt.Stringer interface for the Temperature type
func (t Temperature) String() string {
return fmt.Sprintf("%.1f°C", t.floatVal)
}
// Celsius returns the Temperature value in Celsius
func (t Temperature) Celsius() float64 {
return t.floatVal
}
// CelsiusString returns the Temperature value as Celsius formated string.
//
// This is an alias for the fmt.Stringer interface
func (t Temperature) CelsiusString() string {
return t.String()
}
// Fahrenheit returns the Temperature value in Fahrenheit
func (t Temperature) Fahrenheit() float64 {
return t.floatVal*9/5 + 32
}
// FahrenheitString returns the Temperature value as Fahrenheit formated string.
func (t Temperature) FahrenheitString() string {
return fmt.Sprintf("%.1f°F", t.Fahrenheit())
}