diff --git a/CHANGELOG.md b/CHANGELOG.md index 158aa03..c590a6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ Strictly follows [Semantic Versioning 2.0.0.](https://semver.org/) currencyName: "Netherlands Antillean Guilder", numericCode: 532, minorUnit: 2, - historicalFrom: "2025-07-01" // CHANGED (before: undefined) + historicalFrom: "2025-03-31" // CHANGED (before: undefined) }, // ... other currencies { diff --git a/__tests__/getIso4217Currencies.test.ts b/__tests__/getIso4217Currencies.test.ts index 8a11b42..e5ef080 100644 --- a/__tests__/getIso4217Currencies.test.ts +++ b/__tests__/getIso4217Currencies.test.ts @@ -28,16 +28,16 @@ describe('getIso4217Currencies', () => { expect(countries.find(x => x.alpha3Code === "HRK")).toBeDefined(); }); - test('Caribbean Guilder (XCG) and Netherlands Antillean Guilder (ANG) currencies are returned', () => { - const countries = getIso4217Currencies("2025-03-31"); - expect(countries).toHaveLength(181); - expect(countries.find(x => x.alpha3Code === "XCG")).toBeDefined(); + test('Netherlands Antillean Guilder (ANG) currency is returned', () => { + const countries = getIso4217Currencies("2024-01-01"); + expect(countries).toHaveLength(180); expect(countries.find(x => x.alpha3Code === "ANG")).toBeDefined(); }); - test('Netherlands Antillean Guilder (ANG) currency is no longer returned', () => { - const countries = getIso4217Currencies("2025-07-01"); + test('Caribbean Guilder (XCG) is returned', () => { + const countries = getIso4217Currencies("2025-03-31"); expect(countries).toHaveLength(180); + expect(countries.find(x => x.alpha3Code === "XCG")).toBeDefined(); expect(countries.find(x => x.alpha3Code === "ANG")).toBeUndefined(); }); diff --git a/src/findIso4217Currency.ts b/src/findIso4217Currency.ts index 3279502..6e9777b 100644 --- a/src/findIso4217Currency.ts +++ b/src/findIso4217Currency.ts @@ -3,22 +3,18 @@ import { Iso4217Alpha3Code, Iso4217Currency, Iso4217NumericCode } from "./types/ export function findIso4217Currency(code: Iso4217Alpha3Code | Iso4217NumericCode): Iso4217Currency | undefined { if (code === 532) { - // HINT: edge case with duplicated numeric code (for some period both are active currencies) const xcgCurrency = iso4217Currencies.find(x => x.alpha3Code === "XCG")!; - const angCurrency = iso4217Currencies.find(x => x.alpha3Code === "ANG")!; const now = new Date(); if (now >= new Date(xcgCurrency.introducedIn!)) { - if (new Date(angCurrency.historicalFrom!) <= now) { - console?.warn?.("In the current period there are two active currencies with the same currency numerical code." - + " The new XCG currency is returned for this period, which will ultimately replace ANG." - + " To make sure you select the intended currency please use alpha 3 code."); - } + console?.warn?.("There are two currencies with the same currency numerical code (XCG, ANG)." + + " The new XCG currency is returned which ultimately replaces ANG." + + " To make sure you select the intended currency please use alpha 3 code."); return xcgCurrency; } - return angCurrency; + return iso4217Currencies.find(x => x.alpha3Code === "ANG"); } const predicate: (value: Iso4217Currency) => boolean = diff --git a/src/internal/iso3166CountryToIso4217Currency.ts b/src/internal/iso3166CountryToIso4217Currency.ts index f0a8180..adfea6d 100644 --- a/src/internal/iso3166CountryToIso4217Currency.ts +++ b/src/internal/iso3166CountryToIso4217Currency.ts @@ -2,7 +2,7 @@ import { Iso3166Alpha3Code } from "../types/iso3166"; import { Iso4217Alpha3Code } from "../types/iso4217"; /** @internal */ -export type Iso4217Alpha3CodeResolver = Iso4217Alpha3Code |undefined | ((d: Date) => Iso4217Alpha3Code); +export type Iso4217Alpha3CodeResolver = Iso4217Alpha3Code | undefined | ((d: Date) => Iso4217Alpha3Code); /** @internal */ export const iso3166CountryToIso4217Currency = new Map([ diff --git a/src/internal/iso4217Currencies.ts b/src/internal/iso4217Currencies.ts index ddc5f44..0b577a9 100644 --- a/src/internal/iso4217Currencies.ts +++ b/src/internal/iso4217Currencies.ts @@ -31,7 +31,7 @@ export const iso4217Currencies: Iso4217Currency[] = [ currencyName: "Netherlands Antillean Guilder", numericCode: 532, minorUnit: 2, - historicalFrom: "2025-07-01" + historicalFrom: "2025-03-31" }, { alpha3Code: "AOA",