aboutsummaryrefslogtreecommitdiff
path: root/internal/calendar
diff options
context:
space:
mode:
Diffstat (limited to 'internal/calendar')
-rw-r--r--internal/calendar/datespec.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/internal/calendar/datespec.go b/internal/calendar/datespec.go
index d0040cc..c04bc14 100644
--- a/internal/calendar/datespec.go
+++ b/internal/calendar/datespec.go
@@ -6,6 +6,13 @@ import (
"time"
)
+// ValidDate reports whether spec resolves to a date (validated against a sample
+// year). Used by the `--cal-check` layer linter.
+func ValidDate(spec DateSpec) bool {
+ _, ok := resolveDate(spec, 2025, Easter(2025))
+ return ok
+}
+
// resolveDate returns the date (UTC midnight) that spec names in year, or
// ok=false if the spec is unparseable.
func resolveDate(spec DateSpec, year int, easter time.Time) (time.Time, bool) {
@@ -14,7 +21,7 @@ func resolveDate(spec DateSpec, year int, easter time.Time) (time.Time, bool) {
case len(s) == 5 && s[2] == '-': // MM-DD
mo, err1 := strconv.Atoi(s[0:2])
da, err2 := strconv.Atoi(s[3:5])
- if err1 != nil || err2 != nil {
+ if err1 != nil || err2 != nil || mo < 1 || mo > 12 || da < 1 || da > 31 {
return time.Time{}, false
}
return time.Date(year, time.Month(mo), da, 0, 0, 0, 0, time.UTC), true