From 9a064b55d96db149900ece48ebba36db47534500 Mon Sep 17 00:00:00 2001 From: Terry Yiu Date: Thu, 10 Sep 2026 14:58:45 +0300 Subject: [PATCH] Also filter web currencies by year annotation in their display name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CLDR appends a "(1927–2002)" or "(2009–2024)" style validity-period suffix to a historical/superseded currency's display name — a broader, data-driven signal than the hand-maintained WITHDRAWN_CURRENCY_CODES list, catching ones not added there yet (confirmed AFA, ALK, AOK, AON, AOR, ROL, TRL, RUR, and others all get this treatment). Not a full replacement for the list though: some withdrawn currencies (pre-euro ones especially, e.g. "German Mark" for DEM) carry no such hint in every ICU dataset. Verified with Node against the real Intl.DisplayNames output: matches every year-annotated name actually observed, and produces zero false positives across all 162 currently-formattable codes (Node's Intl.supportedValuesOf('currency') set) — the only two matches were SLL and ZWL, which are already known-withdrawn. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy --- .../xyz/tyiu/satsprice/SystemCurrencies.web.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/shared/src/webMain/kotlin/xyz/tyiu/satsprice/SystemCurrencies.web.kt b/shared/src/webMain/kotlin/xyz/tyiu/satsprice/SystemCurrencies.web.kt index 80cb5cf..9740c7f 100644 --- a/shared/src/webMain/kotlin/xyz/tyiu/satsprice/SystemCurrencies.web.kt +++ b/shared/src/webMain/kotlin/xyz/tyiu/satsprice/SystemCurrencies.web.kt @@ -55,12 +55,25 @@ private val WITHDRAWN_CURRENCY_CODES = setOf( "SKK", // Slovak Koruna ) +/** + * CLDR appends a "(1927–2002)" or "(2009–2024)" style validity-period annotation to a currency's + * display name when it's a historical/superseded one — a broader, data-driven signal than + * [WITHDRAWN_CURRENCY_CODES] above, catching ones not yet added there. Not a full replacement for + * it, though: some withdrawn currencies (pre-euro ones especially) don't get this treatment in + * every ICU dataset and still need an explicit entry — e.g. the year-annotated "Afghan Afghani + * (1927–2002)" is how AFA shows up, but "German Mark" carries no such hint that DEM is withdrawn. + * Dashes vary (an en dash in most of these, an em dash in at least one seen in practice), so the + * character class covers hyphen-minus and both. + */ +private val YEAR_ANNOTATION_REGEX = Regex("""\(\d{4}([-–—]\d{4})?\)$""") + actual fun systemCurrencies(): List = jsSupportedCurrencyCodes() .toList() .map { it.toString() } .filterNot { it in WITHDRAWN_CURRENCY_CODES } .map { code -> CurrencyInfo(code, jsCurrencyDisplayName(code)) } + .filterNot { YEAR_ANNOTATION_REGEX.containsMatchIn(it.displayName) } .sortedBy { it.code } /**