Validate hourly forecast time bounds
This commit is contained in:
@@ -132,6 +132,11 @@ type ForecastPeriod struct {
|
||||
RelativeHumidityPercent *float64 `json:"relativeHumidityPercent,omitempty"`
|
||||
}
|
||||
|
||||
// HasUsableTimeBounds reports whether the period has a non-empty time range.
|
||||
func (p ForecastPeriod) HasUsableTimeBounds() bool {
|
||||
return !p.StartTime.IsZero() && !p.EndTime.IsZero() && p.EndTime.After(p.StartTime)
|
||||
}
|
||||
|
||||
type AlertRun struct {
|
||||
AsOf *time.Time `json:"asOf,omitempty"`
|
||||
Alerts []json.RawMessage `json:"alerts,omitempty"`
|
||||
|
||||
@@ -69,6 +69,30 @@ func TestConvectiveOutlookRunJSONPreservesGeometry(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestForecastPeriodHasUsableTimeBounds(t *testing.T) {
|
||||
start := mustParseBundleTime("2026-05-29T13:00:00Z")
|
||||
end := mustParseBundleTime("2026-05-29T14:00:00Z")
|
||||
tests := []struct {
|
||||
name string
|
||||
period ForecastPeriod
|
||||
want bool
|
||||
}{
|
||||
{name: "valid", period: ForecastPeriod{StartTime: start, EndTime: end}, want: true},
|
||||
{name: "missing start", period: ForecastPeriod{EndTime: end}},
|
||||
{name: "missing end", period: ForecastPeriod{StartTime: start}},
|
||||
{name: "empty range", period: ForecastPeriod{StartTime: start, EndTime: start}},
|
||||
{name: "reversed range", period: ForecastPeriod{StartTime: end, EndTime: start}},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.period.HasUsableTimeBounds(); got != tt.want {
|
||||
t.Fatalf("HasUsableTimeBounds() = %t, want %t", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func mustParseBundleTime(value string) time.Time {
|
||||
parsed, err := time.Parse(time.RFC3339, value)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user