From 0b68ec046c26292e368494e158cc36b342901a80 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 27 Jul 2026 12:21:15 +0200 Subject: feat(calendar): Compute — build celebrations, apply precedence + transfer, cycles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also: deterministic pick tiebreak by slug. --- internal/calendar/precedence.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'internal/calendar/precedence.go') diff --git a/internal/calendar/precedence.go b/internal/calendar/precedence.go index b013b77..7919879 100644 --- a/internal/calendar/precedence.go +++ b/internal/calendar/precedence.go @@ -62,10 +62,18 @@ func precedence(c candidate) int { } // pick returns the highest-precedence candidate as observed and the rest as -// others (commemorations / optional memorials), stably ordered by precedence. +// others (commemorations / optional memorials). Ordering is deterministic: +// by precedence band, then by slug, so equal-band collisions resolve the same +// way on every run. func pick(cands []candidate) (candidate, []candidate) { sorted := make([]candidate, len(cands)) copy(sorted, cands) - sort.SliceStable(sorted, func(i, j int) bool { return precedence(sorted[i]) < precedence(sorted[j]) }) + sort.SliceStable(sorted, func(i, j int) bool { + pi, pj := precedence(sorted[i]), precedence(sorted[j]) + if pi != pj { + return pi < pj + } + return sorted[i].Cel.Slug < sorted[j].Cel.Slug + }) return sorted[0], sorted[1:] } -- cgit v1.3