-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheight.go
87 lines (73 loc) · 2.11 KB
/
height.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// SPDX-FileCopyrightText: 2023 Winni Neessen <wn@neessen.dev>
//
// SPDX-License-Identifier: MIT
package meteologix
import (
"fmt"
"math"
"time"
)
// Height is a type wrapper of an WeatherData for holding height values in WeatherData
// (based on meters a default unit)
type Height WeatherData
// IsAvailable returns true if an Height value was available at time of query
func (h Height) IsAvailable() bool {
return !h.notAvailable
}
// DateTime returns the timestamp associated with the Height value
func (h Height) DateTime() time.Time {
return h.dateTime
}
// String satisfies the fmt.Stringer interface for the Height type
func (h Height) String() string {
return fmt.Sprintf("%.3fm", h.floatVal)
}
// Source returns the Source of Height
//
// If the Source is not available it will return SourceUnknown
func (h Height) Source() Source {
return h.source
}
// Value returns the float64 value of an Height
//
// If the Height is not available in the WeatherData, Value will return math.NaN instead.
func (h Height) Value() float64 {
if h.notAvailable {
return math.NaN()
}
return h.floatVal
}
// Meter returns the Height type value as float64 in meters.
//
// This is an alias for the Value() method
func (h Height) Meter() float64 {
return h.Value()
}
// MeterString returns the Height type as formatted string in meters
//
// This is an alias for the String() method
func (h Height) MeterString() string {
return h.String()
}
// CentiMeter returns the Height type value as float64 in centimeters.
func (h Height) CentiMeter() float64 {
if h.notAvailable {
return math.NaN()
}
return h.floatVal * 100
}
// CentiMeterString returns the Height type as formatted string in centimeters
func (h Height) CentiMeterString() string {
return fmt.Sprintf("%.3fcm", h.CentiMeter())
}
// MilliMeter returns the Height type value as float64 in milliimeters.
func (h Height) MilliMeter() float64 {
if h.notAvailable {
return math.NaN()
}
return h.floatVal * 1000
}
// MilliMeterString returns the Height type as formatted string in millimeters
func (h Height) MilliMeterString() string {
return fmt.Sprintf("%.3fmm", h.MilliMeter())
}