-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
921538d
commit a6317e5
Showing
9 changed files
with
442 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
import { convertToDate } from "./internal/convertToDate"; | ||
import { iso4217Currencies } from "./internal/iso4217Currencies"; | ||
import { DateIsoString } from "./types/dateIsoString"; | ||
import { Iso4217Currency } from "./types/iso4217"; | ||
|
||
export function getIso4217Currencies(): Iso4217Currency[] { | ||
return iso4217Currencies; | ||
const _cache: Record<string, Iso4217Currency[]> = {}; | ||
|
||
export function getIso4217Currencies(statusForTheDay?: Date | DateIsoString): Iso4217Currency[] { | ||
const limit = statusForTheDay ? convertToDate(statusForTheDay) : new Date(), | ||
year = limit.getFullYear(), | ||
month = limit.getMonth() + 1, | ||
day = limit.getDate(); | ||
|
||
const dateKey = `${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}`; | ||
const cachedResult = _cache[dateKey]; | ||
|
||
if (cachedResult) { | ||
return cachedResult; | ||
} | ||
|
||
const list = iso4217Currencies.filter(x => (!x.historicalFrom || x.historicalFrom > dateKey) | ||
&& (!x.introducedIn || x.introducedIn <= dateKey)); | ||
|
||
_cache[dateKey] = list; | ||
|
||
return list; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.