Skip to content

Commit

Permalink
new feature: currency XCG
Browse files Browse the repository at this point in the history
- historical date adjustment
  • Loading branch information
karczk-dnv committed Dec 11, 2023
1 parent 86cceb8 commit 9a4250a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 6 additions & 6 deletions __tests__/getIso4217Currencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
12 changes: 4 additions & 8 deletions src/findIso4217Currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion src/internal/iso3166CountryToIso4217Currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Iso3166Alpha3Code, Iso4217Alpha3CodeResolver>([
Expand Down
2 changes: 1 addition & 1 deletion src/internal/iso4217Currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9a4250a

Please sign in to comment.