go-meteologix/radiation.go

49 lines
1.1 KiB
Go
Raw Permalink Normal View History

// 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
}
// 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
}
// Value returns the float64 value of an Radiation
// If the Radiation is not available in the WeatherData
// Vaule will return math.NaN instead.
2023-05-23 20:00:42 +02:00
func (r Radiation) Value() float64 {
if r.na {
return math.NaN()
}
return r.fv
}
// String satisfies the fmt.Stringer interface for the Radiation type
2023-05-23 20:00:42 +02:00
func (r Radiation) String() string {
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
}