Skip to content

Commit 9a4250a

Browse files
committed
new feature: currency XCG
- historical date adjustment
1 parent 86cceb8 commit 9a4250a

5 files changed

+13
-17
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Strictly follows [Semantic Versioning 2.0.0.](https://semver.org/)
1313
currencyName: "Netherlands Antillean Guilder",
1414
numericCode: 532,
1515
minorUnit: 2,
16-
historicalFrom: "2025-07-01" // CHANGED (before: undefined)
16+
historicalFrom: "2025-03-31" // CHANGED (before: undefined)
1717
},
1818
// ... other currencies
1919
{

__tests__/getIso4217Currencies.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ describe('getIso4217Currencies', () => {
2828
expect(countries.find(x => x.alpha3Code === "HRK")).toBeDefined();
2929
});
3030

31-
test('Caribbean Guilder (XCG) and Netherlands Antillean Guilder (ANG) currencies are returned', () => {
32-
const countries = getIso4217Currencies("2025-03-31");
33-
expect(countries).toHaveLength(181);
34-
expect(countries.find(x => x.alpha3Code === "XCG")).toBeDefined();
31+
test('Netherlands Antillean Guilder (ANG) currency is returned', () => {
32+
const countries = getIso4217Currencies("2024-01-01");
33+
expect(countries).toHaveLength(180);
3534
expect(countries.find(x => x.alpha3Code === "ANG")).toBeDefined();
3635
});
3736

38-
test('Netherlands Antillean Guilder (ANG) currency is no longer returned', () => {
39-
const countries = getIso4217Currencies("2025-07-01");
37+
test('Caribbean Guilder (XCG) is returned', () => {
38+
const countries = getIso4217Currencies("2025-03-31");
4039
expect(countries).toHaveLength(180);
40+
expect(countries.find(x => x.alpha3Code === "XCG")).toBeDefined();
4141
expect(countries.find(x => x.alpha3Code === "ANG")).toBeUndefined();
4242
});
4343

src/findIso4217Currency.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@ import { Iso4217Alpha3Code, Iso4217Currency, Iso4217NumericCode } from "./types/
33

44
export function findIso4217Currency(code: Iso4217Alpha3Code | Iso4217NumericCode): Iso4217Currency | undefined {
55
if (code === 532) {
6-
// HINT: edge case with duplicated numeric code (for some period both are active currencies)
76
const xcgCurrency = iso4217Currencies.find(x => x.alpha3Code === "XCG")!;
8-
const angCurrency = iso4217Currencies.find(x => x.alpha3Code === "ANG")!;
97
const now = new Date();
108

119
if (now >= new Date(xcgCurrency.introducedIn!)) {
12-
if (new Date(angCurrency.historicalFrom!) <= now) {
13-
console?.warn?.("In the current period there are two active currencies with the same currency numerical code."
14-
+ " The new XCG currency is returned for this period, which will ultimately replace ANG."
15-
+ " To make sure you select the intended currency please use alpha 3 code.");
16-
}
10+
console?.warn?.("There are two currencies with the same currency numerical code (XCG, ANG)."
11+
+ " The new XCG currency is returned which ultimately replaces ANG."
12+
+ " To make sure you select the intended currency please use alpha 3 code.");
1713

1814
return xcgCurrency;
1915
}
2016

21-
return angCurrency;
17+
return iso4217Currencies.find(x => x.alpha3Code === "ANG");
2218
}
2319

2420
const predicate: (value: Iso4217Currency) => boolean =

src/internal/iso3166CountryToIso4217Currency.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Iso3166Alpha3Code } from "../types/iso3166";
22
import { Iso4217Alpha3Code } from "../types/iso4217";
33

44
/** @internal */
5-
export type Iso4217Alpha3CodeResolver = Iso4217Alpha3Code |undefined | ((d: Date) => Iso4217Alpha3Code);
5+
export type Iso4217Alpha3CodeResolver = Iso4217Alpha3Code | undefined | ((d: Date) => Iso4217Alpha3Code);
66

77
/** @internal */
88
export const iso3166CountryToIso4217Currency = new Map<Iso3166Alpha3Code, Iso4217Alpha3CodeResolver>([

src/internal/iso4217Currencies.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const iso4217Currencies: Iso4217Currency[] = [
3131
currencyName: "Netherlands Antillean Guilder",
3232
numericCode: 532,
3333
minorUnit: 2,
34-
historicalFrom: "2025-07-01"
34+
historicalFrom: "2025-03-31"
3535
},
3636
{
3737
alpha3Code: "AOA",

0 commit comments

Comments
 (0)