-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced a new `Duration` type for handling sun hours data points in weather forecasts. Updated the `WeatherForecastDatapoint` struct and relevant methods to support this new data point, ensuring proper retrieval and availability checks.
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-FileCopyrightText: 2023 Winni Neessen <wn@neessen.dev> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package meteologix | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"time" | ||
) | ||
|
||
// Duration is a type wrapper of an WeatherData for holding height values in WeatherData | ||
// (based on meters a default unit) | ||
type Duration WeatherData | ||
|
||
// IsAvailable returns true if an Duration value was available at time of query | ||
func (d Duration) IsAvailable() bool { | ||
return !d.notAvailable | ||
} | ||
|
||
// DateTime returns the timestamp associated with the Duration value | ||
func (d Duration) DateTime() time.Time { | ||
return d.dateTime | ||
} | ||
|
||
// String satisfies the fmt.Stringer interface for the Duration type | ||
func (d Duration) String() string { | ||
return fmt.Sprintf("%.2fh", d.floatVal) | ||
} | ||
|
||
// Source returns the Source of Duration | ||
// | ||
// If the Source is not available it will return SourceUnknown | ||
func (d Duration) Source() Source { | ||
return d.source | ||
} | ||
|
||
// Value returns the float64 value of an Duration | ||
// | ||
// If the Duration is not available in the WeatherData, Value will return math.NaN instead. | ||
func (d Duration) Value() float64 { | ||
if d.notAvailable { | ||
return math.NaN() | ||
} | ||
return d.floatVal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters