2023-05-22 17:13:36 +02:00
|
|
|
// SPDX-FileCopyrightText: 2023 Winni Neessen <wn@neessen.dev>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package meteologix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Radiation is a type wrapper of an WeatherData for holding radiation
|
|
|
|
// values in WeatherData
|
|
|
|
type Radiation WeatherData
|
|
|
|
|
|
|
|
// IsAvailable returns true if an Radiation value was
|
|
|
|
// available at time of query
|
2023-05-23 20:00:42 +02:00
|
|
|
func (r Radiation) IsAvailable() bool {
|
|
|
|
return !r.na
|
2023-05-22 17:13:36 +02:00
|
|
|
}
|
|
|
|
|
2023-06-27 19:01:37 +02:00
|
|
|
// DateTime returns the time.Time object representing the date and time
|
|
|
|
// at which the Radiation value was queried
|
2023-05-23 20:00:42 +02:00
|
|
|
func (r Radiation) DateTime() time.Time {
|
|
|
|
return r.dt
|
2023-05-22 17:13:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Value returns the float64 value of an Radiation
|
2023-06-26 12:21:36 +02:00
|
|
|
// If the Radiation is not available in the WeatherData
|
2023-05-22 17:13:36 +02:00
|
|
|
// Vaule will return math.NaN instead.
|
2023-05-23 20:00:42 +02:00
|
|
|
func (r Radiation) Value() float64 {
|
|
|
|
if r.na {
|
2023-05-22 17:13:36 +02:00
|
|
|
return math.NaN()
|
|
|
|
}
|
2023-05-24 22:00:47 +02:00
|
|
|
return r.fv
|
2023-05-22 17:13:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// String satisfies the fmt.Stringer interface for the Radiation type
|
2023-05-23 20:00:42 +02:00
|
|
|
func (r Radiation) String() string {
|
2023-05-24 22:00:47 +02:00
|
|
|
return fmt.Sprintf("%.0fkJ/m²", r.fv)
|
2023-05-23 20:00:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Source returns the Source of Pressure
|
|
|
|
// If the Source is not available it will return SourceUnknown
|
|
|
|
func (r Radiation) Source() Source {
|
|
|
|
return r.s
|
2023-05-22 17:13:36 +02:00
|
|
|
}
|