diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-27 12:21:15 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-27 12:21:15 +0200 |
| commit | 0b68ec046c26292e368494e158cc36b342901a80 (patch) | |
| tree | 87f6d9ba73c9ce827c263915e1ad511ba61084e8 /internal/calendar/precedence.go | |
| parent | 4c08e94dbcce8dc7757afba3001abe509bd2b6a8 (diff) | |
| download | lectio-0b68ec046c26292e368494e158cc36b342901a80.tar.gz lectio-0b68ec046c26292e368494e158cc36b342901a80.zip | |
feat(calendar): Compute — build celebrations, apply precedence + transfer, cycles
Also: deterministic pick tiebreak by slug.
Diffstat (limited to 'internal/calendar/precedence.go')
| -rw-r--r-- | internal/calendar/precedence.go | 12 |
1 files changed, 10 insertions, 2 deletions
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:] } |
