diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-27 13:23:51 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-27 13:23:51 +0200 |
| commit | e91a7dadb4401a553ffdd4f3661640921e425eb6 (patch) | |
| tree | 94df3ed52204c186c505a19e1efc650895edf795 /internal/calendar/datespec.go | |
| parent | fb3fdc69fad0f374c419559d99d75ba8c81aa632 (diff) | |
| download | lectio-e91a7dadb4401a553ffdd4f3661640921e425eb6.tar.gz lectio-e91a7dadb4401a553ffdd4f3661640921e425eb6.zip | |
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).
Diffstat (limited to 'internal/calendar/datespec.go')
| -rw-r--r-- | internal/calendar/datespec.go | 9 |
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 |
