go-meteologix/datetime.go

41 lines
987 B
Go
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Winni Neessen <wn@neessen.dev>
//
// SPDX-License-Identifier: MIT
package meteologix
import (
"time"
)
// DateTime is a type wrapper of an WeatherData for holding datetime
// values in WeatherData
type DateTime WeatherData
// IsAvailable returns true if an Direction value was
// available at time of query
func (dt DateTime) IsAvailable() bool {
return !dt.na
}
2023-05-30 14:29:31 +02:00
// DateTime returns the timestamp for that specific DateTime type
func (dt DateTime) DateTime() time.Time {
return dt.dt
}
// Value returns the time.Time value of an DateTime value
// If the DateTime is not available in the WeatherData
// Value will return time.Time with a zero value instead.
func (dt DateTime) Value() time.Time {
if dt.na {
return time.Time{}
}
return dt.dv
}
2023-05-28 23:39:11 +02:00
// String satisfies the fmt.Stringer interface for the DateTime type
// The date will returned as time.RFC3339 format
func (dt DateTime) String() string {
return dt.Value().Format(time.RFC3339)
}