Skip to content

Commit 778533c

Browse files
committed
Fix country/currency map generation when CLDR data is incomplete.
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.
1 parent cf9e73a commit 778533c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

data.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ func generateCountryCurrencies(dir string) (map[string]string, error) {
396396
Supplemental struct {
397397
CurrencyData struct {
398398
Region map[string][]map[string]struct {
399+
From string `json:"_from"`
399400
To string `json:"_to"`
400401
Tender string `json:"_tender"`
401402
}
@@ -414,11 +415,16 @@ func generateCountryCurrencies(dir string) (map[string]string, error) {
414415
}
415416

416417
lastCurrencyCode := ""
418+
lastFrom := ""
417419
for _, currencyUsage := range currencies {
418420
for currencyCode, usageInfo := range currencyUsage {
419-
// If there's no "to" date, then this currency is still in use.
420-
if usageInfo.To == "" && usageInfo.Tender != "false" {
421+
if usageInfo.To != "" || usageInfo.Tender == "false" {
422+
// Currency no longer in use, skip.
423+
continue
424+
}
425+
if lastFrom == "" || usageInfo.From > lastFrom {
421426
lastCurrencyCode = currencyCode
427+
lastFrom = usageInfo.From
422428
}
423429
}
424430
}

0 commit comments

Comments
 (0)