fix(go): accept single-digit day/month in attendance date headers
All checks were successful
Deploy to K8s / deploy (push) Successful in 8s
All checks were successful
Deploy to K8s / deploy (push) Successful in 8s
parseDates was using "02.01.2006" / "01/02/2006" which require zero-padded fields. The Czech attendance sheet headers contain dates like "1.6.2026", "23.3.2026", "6.4.2026" — Go silently dropped those columns while Python's strptime accepted them. Effect was a missing 2026-06 month on /api/juniors plus undercounted attendance in any month with single-digit columns; surfaced via make parity. Use the unpadded reference forms "2.1.2006" / "1/2/2006" instead — Go's time.Parse accepts both padded and unpadded inputs against them. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -142,7 +142,13 @@ func parseDates(header []string) []struct {
|
||||
}
|
||||
var dt time.Time
|
||||
var err error
|
||||
for _, fmt_ := range []string{"02.01.2006", "01/02/2006"} {
|
||||
// Use the unpadded reference forms ("2.1" and "1/2"): Go's time.Parse
|
||||
// accepts both single-digit and zero-padded inputs against them, so
|
||||
// "1.6.2026", "01.06.2026", "23.3.2026" all parse. Czech sheet authors
|
||||
// drop the leading zero on dates ≤ 9 — Python's strptime is lenient
|
||||
// the same way; the previous "02.01.2006" form silently dropped those
|
||||
// columns and undercounted attendance.
|
||||
for _, fmt_ := range []string{"2.1.2006", "1/2/2006"} {
|
||||
dt, err = time.Parse(fmt_, raw)
|
||||
if err == nil {
|
||||
break
|
||||
|
||||
@@ -174,6 +174,28 @@ func TestLoadExceptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseDates_SingleDigitDayMonth covers the regression where Go's strict
|
||||
// "02.01.2006" format dropped header cells written without leading zeros
|
||||
// (e.g. "1.6.2026", "23.3.2026"), causing attendance undercounts and missing
|
||||
// months on the /api/juniors response. Czech sheet authors drop the zero
|
||||
// pad freely; Python's strptime tolerates it, so the parsers must match.
|
||||
func TestParseDates_SingleDigitDayMonth(t *testing.T) {
|
||||
// Czech form ("DD.MM.YYYY", with leading zeros optional) is the primary
|
||||
// path. The "M/D/YYYY" fallback mirrors Python's %m/%d/%Y secondary
|
||||
// strptime branch — month-first, day-second.
|
||||
header := []string{"Jméno", "Tier", "", "01.06.2026", "1.6.2026", "23.3.2026", "6.4.2026", "01/02/2026", "1/2/2026"}
|
||||
got := parseDates(header)
|
||||
want := []string{"2026-06", "2026-06", "2026-03", "2026-04", "2026-01", "2026-01"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("parseDates: got %d entries, want %d (%v)", len(got), len(want), got)
|
||||
}
|
||||
for i, e := range got {
|
||||
if e.month != want[i] {
|
||||
t.Errorf("parseDates[%d].month = %q, want %q (raw=%q)", i, e.month, want[i], header[e.col])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TTL smoke test: second call within TTL must not call fetch again.
|
||||
func TestLoadAdults_CacheHit(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user