go-meteologix/precipitation.go
Winni Neessen c9d95300c2
Refine Precipitation's DateTime method comment
The Precipitation's DateTime method comment was adjusted to better reflect its functionality. Instead of stating it returns true if the precipitation data was available at the time of the query or not, it was clarified that the method actually returns the DateTime when the Precipitation value was recorded.
2023-06-27 18:57:33 +02:00

48 lines
1.1 KiB
Go

// 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
func (p Precipitation) IsAvailable() bool {
return !p.na
}
// DateTime returns the DateTime when the Precipitation value was recorded
func (p Precipitation) DateTime() time.Time {
return p.dt
}
// String satisfies the fmt.Stringer interface for the Precipitation type
func (p Precipitation) String() string {
return fmt.Sprintf("%.1fmm", p.fv)
}
// 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.
func (p Precipitation) Value() float64 {
if p.na {
return math.NaN()
}
return p.fv
}