go-meteologix/precipitation.go

48 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"
)
// Precipitation is a type wrapper of an WeatherData for holding precipitation
// values in WeatherData
type Precipitation WeatherData
// IsAvailable returns true if an Precipitation value was
// available at time of query
2023-05-23 20:00:42 +02:00
func (p Precipitation) IsAvailable() bool {
return !p.na
}
// DateTime returns the DateTime when the Precipitation value was recorded
2023-05-23 20:00:42 +02:00
func (p Precipitation) DateTime() time.Time {
return p.dt
}
// String satisfies the fmt.Stringer interface for the Precipitation type
2023-05-23 20:00:42 +02:00
func (p Precipitation) String() string {
return fmt.Sprintf("%.1fmm", p.fv)
2023-05-23 20:00:42 +02:00
}
// Source returns the Source of Precipitation
// If the Source is not available it will return SourceUnknown
func (p Precipitation) Source() Source {
return p.s
}
// Value returns the float64 value of an Precipitation
// If the Precipitation is not available in the WeatherData
// Vaule will return math.NaN instead.
2023-05-23 20:00:42 +02:00
func (p Precipitation) Value() float64 {
if p.na {
return math.NaN()
}
return p.fv
}