Add forecast daypart derivation
This commit is contained in:
@@ -3,7 +3,6 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/timeutil"
|
||||
@@ -69,10 +68,10 @@ func Validate(cfg Config) error {
|
||||
if strings.TrimSpace(daypart.Name) == "" {
|
||||
return fmt.Errorf("dayparts[%d].name is required", i)
|
||||
}
|
||||
if err := validateClockTime(daypart.Start); err != nil {
|
||||
if _, err := timeutil.ParseClock(daypart.Start); err != nil {
|
||||
return fmt.Errorf("dayparts[%d].start is invalid: %w", i, err)
|
||||
}
|
||||
if err := validateClockTime(daypart.End); err != nil {
|
||||
if _, err := timeutil.ParseClock(daypart.End); err != nil {
|
||||
return fmt.Errorf("dayparts[%d].end is invalid: %w", i, err)
|
||||
}
|
||||
}
|
||||
@@ -87,28 +86,3 @@ func validatePolicy(name string, policy MissingSourcePolicy) error {
|
||||
return fmt.Errorf("%s must be one of error, warn, or none", name)
|
||||
}
|
||||
}
|
||||
|
||||
func validateClockTime(value string) error {
|
||||
parts := strings.Split(value, ":")
|
||||
if len(parts) != 2 {
|
||||
return fmt.Errorf("expected HH:MM")
|
||||
}
|
||||
hour, err := strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid hour")
|
||||
}
|
||||
minute, err := strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid minute")
|
||||
}
|
||||
if hour < 0 || hour > 24 {
|
||||
return fmt.Errorf("hour must be between 00 and 24")
|
||||
}
|
||||
if minute < 0 || minute > 59 {
|
||||
return fmt.Errorf("minute must be between 00 and 59")
|
||||
}
|
||||
if hour == 24 && minute != 0 {
|
||||
return fmt.Errorf("24 is only valid as 24:00")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user