Skip to content

Commit

Permalink
Fix country/currency map generation when CLDR data is incomplete.
Browse files Browse the repository at this point in the history
A number of countries (BT, LS, NA) have historical currency usage entries
without a _to date, making it seem like those currencies are still in use.
We now grab the currency with the most recent _from date.
  • Loading branch information
bojanz committed Apr 19, 2024
1 parent cf9e73a commit 778533c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ func generateCountryCurrencies(dir string) (map[string]string, error) {
Supplemental struct {
CurrencyData struct {
Region map[string][]map[string]struct {
From string `json:"_from"`
To string `json:"_to"`
Tender string `json:"_tender"`
}
Expand All @@ -414,11 +415,16 @@ func generateCountryCurrencies(dir string) (map[string]string, error) {
}

lastCurrencyCode := ""
lastFrom := ""
for _, currencyUsage := range currencies {
for currencyCode, usageInfo := range currencyUsage {
// If there's no "to" date, then this currency is still in use.
if usageInfo.To == "" && usageInfo.Tender != "false" {
if usageInfo.To != "" || usageInfo.Tender == "false" {
// Currency no longer in use, skip.
continue
}
if lastFrom == "" || usageInfo.From > lastFrom {
lastCurrencyCode = currencyCode
lastFrom = usageInfo.From
}
}
}
Expand Down

0 comments on commit 778533c

Please sign in to comment.