From e91a7dadb4401a553ffdd4f3661640921e425eb6 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 27 Jul 2026 13:23:51 +0200 Subject: feat(cli): --cal-new scaffold + --cal-check lint for custom calendar layers Also: reject out-of-range MM-DD in resolveDate (strict validation for user data). --- internal/calendar/datespec.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'internal/calendar/datespec.go') 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 -- cgit v1.3