Skip to content

feat(api): clamp out-of-range construction year to nearest TABULA period - #36

Merged
jravani merged 1 commit into
mainfrom
feat/clamp-out-of-range-construction-year
Sep 8, 2026
Merged

jravani merged 1 commit into
mainfrom
feat/clamp-out-of-range-construction-year

Conversation

@jravani

@jravani jravani commented Sep 8, 2026

Copy link
Copy Markdown
Member

Problem

GET /api/v1/variants/{iso2}/match?type=&year= returned an empty match
list whenever no period band for the requested type covered the given
year. 27 of 93 country+type period sets in the TABULA workbook have no
open-ended (0 or 9999) sentinel band at one or both ends, so a year
before or after the type's recorded range never matched anything
(DE.N.AB only covers 1860-1978, BE.N.AB only covers 1946 onward).

Change

ResolvePeriodByYear now clamps a year outside every band for a type
to the nearest edge: below the oldest band resolves to the oldest
period, above the newest resolves to the newest. A year inside the
type's overall range but falling in a gap between two defined bands is
left as a genuine no-match, since which neighbouring band to prefer
there is undefined.

Also adds input guards on the year query parameter: it must be a
non-negative integer and must not exceed the current calendar year.

Testing

  • go test ./...
  • go test -tags integration -v -timeout 10m ./internal/db/repository/
  • Verified the new integration test cases fail against the pre-fix code
    and pass after the fix.

Closes #34

GET /api/v1/variants/{iso2}/match?type=&year= returned an empty match
list whenever no period band for the requested type covered the given
year. 27 of 93 country+type period sets in the TABULA workbook have no
open-ended (0 or 9999) sentinel band at one or both ends, so a year
before or after the type's recorded range never matched anything
(DE.N.AB only covers 1860-1978, BE.N.AB only covers 1946 onward).

ResolvePeriodByYear now clamps a year outside every band for a type to
the nearest edge: below the oldest band resolves to the oldest period,
above the newest resolves to the newest. A year inside the type's
overall range but falling in a gap between two defined bands is left
as a genuine no-match, since which neighbouring band to prefer there
is undefined.

Also add input guards on the year query parameter: it must be a
non-negative integer and must not exceed the current calendar year.

Closes #34
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.78261% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/db/repository/tabula_repository.go 82.50% 3 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@jravani
jravani merged commit bcd03e0 into main Sep 8, 2026
6 checks passed
@jravani
jravani deleted the feat/clamp-out-of-range-construction-year branch September 8, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clamp out-of-range construction year to the nearest TABULA period

2 participants