@riocrypto/common 1.0.2573 → 1.0.2578
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/helpers/get-two-way-settlement-date-offset-from-date.d.ts +19 -0
- package/build/helpers/get-two-way-settlement-date-offset-from-date.js +47 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/types/address-verification.d.ts +1 -0
- package/build/types/bank-account-verification.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Country } from "../types/country";
|
|
2
|
+
/**
|
|
3
|
+
* Given a desired two-way settlement value date (in the country's local
|
|
4
|
+
* calendar), returns the smallest business-day offset N such that
|
|
5
|
+
* getDaysUntilTwoWaySettlementDate({ ..., twoWaySettlementDateOffset: N })
|
|
6
|
+
* resolves to that same date. Mirrors the forward mapping exactly, including
|
|
7
|
+
* the "offset 0 = today or next business day" and the Asia-time +1
|
|
8
|
+
* adjustment, so round-tripping is consistent.
|
|
9
|
+
*
|
|
10
|
+
* Returns undefined if the target date is in the past, falls on a
|
|
11
|
+
* weekend/holiday, or lies beyond MAX_OFFSET business days from today.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getTwoWaySettlementDateOffsetFromDate: ({ country, holidays, targetDate, }: {
|
|
14
|
+
country: Country;
|
|
15
|
+
holidays: {
|
|
16
|
+
dates: string[];
|
|
17
|
+
};
|
|
18
|
+
targetDate: Date;
|
|
19
|
+
}) => number | undefined;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTwoWaySettlementDateOffsetFromDate = void 0;
|
|
4
|
+
const two_way_settlement_type_1 = require("../types/two-way-settlement-type");
|
|
5
|
+
const get_country_timezone_1 = require("./get-country-timezone");
|
|
6
|
+
const get_days_until_two_way_settlement_date_1 = require("./get-days-until-two-way-settlement-date");
|
|
7
|
+
const MAX_OFFSET = 1000;
|
|
8
|
+
const formatLocalDate = (date) => {
|
|
9
|
+
const year = date.getFullYear();
|
|
10
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
11
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
12
|
+
return `${year}-${month}-${day}`;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Given a desired two-way settlement value date (in the country's local
|
|
16
|
+
* calendar), returns the smallest business-day offset N such that
|
|
17
|
+
* getDaysUntilTwoWaySettlementDate({ ..., twoWaySettlementDateOffset: N })
|
|
18
|
+
* resolves to that same date. Mirrors the forward mapping exactly, including
|
|
19
|
+
* the "offset 0 = today or next business day" and the Asia-time +1
|
|
20
|
+
* adjustment, so round-tripping is consistent.
|
|
21
|
+
*
|
|
22
|
+
* Returns undefined if the target date is in the past, falls on a
|
|
23
|
+
* weekend/holiday, or lies beyond MAX_OFFSET business days from today.
|
|
24
|
+
*/
|
|
25
|
+
const getTwoWaySettlementDateOffsetFromDate = ({ country, holidays, targetDate, }) => {
|
|
26
|
+
const timezone = (0, get_country_timezone_1.getCountryTimezone)(country);
|
|
27
|
+
const now = new Date();
|
|
28
|
+
const todayInCountryTZ = new Date(now.toLocaleString("en-US", { timeZone: timezone }));
|
|
29
|
+
const targetKey = formatLocalDate(targetDate);
|
|
30
|
+
for (let offset = 0; offset <= MAX_OFFSET; offset++) {
|
|
31
|
+
const daysUntil = (0, get_days_until_two_way_settlement_date_1.getDaysUntilTwoWaySettlementDate)({
|
|
32
|
+
country,
|
|
33
|
+
holidays,
|
|
34
|
+
twoWaySettlementDateOffset: offset,
|
|
35
|
+
twoWaySettlementType: two_way_settlement_type_1.TwoWaySettlementType.TPlusOffset,
|
|
36
|
+
});
|
|
37
|
+
const candidate = new Date(todayInCountryTZ);
|
|
38
|
+
candidate.setDate(candidate.getDate() + daysUntil);
|
|
39
|
+
const candidateKey = formatLocalDate(candidate);
|
|
40
|
+
if (candidateKey === targetKey)
|
|
41
|
+
return offset;
|
|
42
|
+
if (candidateKey > targetKey)
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
};
|
|
47
|
+
exports.getTwoWaySettlementDateOffsetFromDate = getTwoWaySettlementDateOffsetFromDate;
|
package/build/index.d.ts
CHANGED
|
@@ -539,6 +539,7 @@ export * from "./helpers/should-add-one-day-to-settlement-date";
|
|
|
539
539
|
export * from "./helpers/get-country-timezone";
|
|
540
540
|
export * from "./helpers/get-days-between-agreed-two-way-settlement-date-and-payment-date";
|
|
541
541
|
export * from "./helpers/get-days-until-two-way-settlement-date";
|
|
542
|
+
export * from "./helpers/get-two-way-settlement-date-offset-from-date";
|
|
542
543
|
export * from "./helpers/get-two-way-settlement-date";
|
|
543
544
|
export * from "./helpers/get-order-status-rankings";
|
|
544
545
|
export * from "./helpers/get-lower-order-statuses";
|
package/build/index.js
CHANGED
|
@@ -555,6 +555,7 @@ __exportStar(require("./helpers/should-add-one-day-to-settlement-date"), exports
|
|
|
555
555
|
__exportStar(require("./helpers/get-country-timezone"), exports);
|
|
556
556
|
__exportStar(require("./helpers/get-days-between-agreed-two-way-settlement-date-and-payment-date"), exports);
|
|
557
557
|
__exportStar(require("./helpers/get-days-until-two-way-settlement-date"), exports);
|
|
558
|
+
__exportStar(require("./helpers/get-two-way-settlement-date-offset-from-date"), exports);
|
|
558
559
|
__exportStar(require("./helpers/get-two-way-settlement-date"), exports);
|
|
559
560
|
__exportStar(require("./helpers/get-order-status-rankings"), exports);
|
|
560
561
|
__exportStar(require("./helpers/get-lower-order-statuses"), exports);
|