@riocrypto/common 1.0.2735 → 1.0.2736

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.
@@ -10,25 +10,27 @@ const formatLocalDate = (date) => {
10
10
  return `${year}-${month}-${day}`;
11
11
  };
12
12
  const getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate = ({ country, holidays, twoWaySettlementDate, deferredPaymentType, }) => {
13
- if (deferredPaymentType !== deferred_payment_type_1.DeferredPaymentType.OneDayAfter) {
13
+ const businessDaysToAdd = (0, deferred_payment_type_1.getDeferredPaymentBusinessDays)(deferredPaymentType);
14
+ if (businessDaysToAdd === 0) {
14
15
  return 0;
15
16
  }
16
17
  const timezone = (0, get_country_timezone_1.getCountryTimezone)(country);
17
18
  // Convert the two way settlement date to the country's timezone
18
19
  const settlementDateInCountryTZ = new Date(twoWaySettlementDate.toLocaleString("en-US", { timeZone: timezone }));
19
- // Find the next business day after the settlement date
20
- const nextBusinessDay = new Date(settlementDateInCountryTZ);
21
- nextBusinessDay.setDate(settlementDateInCountryTZ.getDate() + 1);
22
- while (true) {
23
- const isWeekend = nextBusinessDay.getDay() === 0 || nextBusinessDay.getDay() === 6;
24
- const isHoliday = holidays.dates.includes(formatLocalDate(nextBusinessDay));
20
+ // Walk forward one calendar day at a time, counting only business days,
21
+ // until the requested number of business days has been reached
22
+ const paymentDate = new Date(settlementDateInCountryTZ);
23
+ let businessDaysFound = 0;
24
+ while (businessDaysFound < businessDaysToAdd) {
25
+ paymentDate.setDate(paymentDate.getDate() + 1);
26
+ const isWeekend = paymentDate.getDay() === 0 || paymentDate.getDay() === 6;
27
+ const isHoliday = holidays.dates.includes(formatLocalDate(paymentDate));
25
28
  if (!isWeekend && !isHoliday) {
26
- break; // Found the next business day
29
+ businessDaysFound++;
27
30
  }
28
- nextBusinessDay.setDate(nextBusinessDay.getDate() + 1);
29
31
  }
30
- // Calculate the calendar days difference between settlement date and next business day
31
- const timeDifference = nextBusinessDay.getTime() - settlementDateInCountryTZ.getTime();
32
+ // Calculate the calendar days difference between settlement date and payment date
33
+ const timeDifference = paymentDate.getTime() - settlementDateInCountryTZ.getTime();
32
34
  const daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24));
33
35
  return daysDifference;
34
36
  };
@@ -1,5 +1,7 @@
1
1
  export declare enum DeferredPaymentType {
2
2
  None = "none",
3
3
  EndOfDay = "endOfDay",
4
- OneDayAfter = "oneDayAfter"
4
+ OneDayAfter = "oneDayAfter",
5
+ TwoDaysAfter = "twoDaysAfter"
5
6
  }
7
+ export declare const getDeferredPaymentBusinessDays: (deferredPaymentType: DeferredPaymentType) => number;
@@ -1,9 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeferredPaymentType = void 0;
3
+ exports.getDeferredPaymentBusinessDays = exports.DeferredPaymentType = void 0;
4
4
  var DeferredPaymentType;
5
5
  (function (DeferredPaymentType) {
6
6
  DeferredPaymentType["None"] = "none";
7
7
  DeferredPaymentType["EndOfDay"] = "endOfDay";
8
8
  DeferredPaymentType["OneDayAfter"] = "oneDayAfter";
9
+ DeferredPaymentType["TwoDaysAfter"] = "twoDaysAfter";
9
10
  })(DeferredPaymentType = exports.DeferredPaymentType || (exports.DeferredPaymentType = {}));
11
+ const getDeferredPaymentBusinessDays = (deferredPaymentType) => {
12
+ switch (deferredPaymentType) {
13
+ case DeferredPaymentType.OneDayAfter:
14
+ return 1;
15
+ case DeferredPaymentType.TwoDaysAfter:
16
+ return 2;
17
+ default:
18
+ return 0;
19
+ }
20
+ };
21
+ exports.getDeferredPaymentBusinessDays = getDeferredPaymentBusinessDays;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.2735",
3
+ "version": "1.0.2736",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",