@discomedia/utils 1.0.51 → 1.0.52
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/dist/index-frontend.cjs +12 -5
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +12 -5
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +12 -5
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/dist/test.js +39 -8
- package/dist/test.js.map +1 -1
- package/dist/types/market-time.d.ts +6 -6
- package/dist/types/market-time.d.ts.map +1 -1
- package/dist/types/types/market-time-types.d.ts +5 -0
- package/dist/types/types/market-time-types.d.ts.map +1 -1
- package/dist/types-frontend/market-time.d.ts +6 -6
- package/dist/types-frontend/market-time.d.ts.map +1 -1
- package/dist/types-frontend/types/market-time-types.d.ts +5 -0
- package/dist/types-frontend/types/market-time-types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index-frontend.cjs
CHANGED
|
@@ -9385,10 +9385,13 @@ function countTradingDays(startDate, endDate = new Date()) {
|
|
|
9385
9385
|
/**
|
|
9386
9386
|
* Returns the trading day N days back from a reference date, along with its market open time.
|
|
9387
9387
|
* Trading days are counted as full or half trading days (days that end count as 1 full trading day).
|
|
9388
|
+
* By default, the most recent completed trading day counts as day 1.
|
|
9389
|
+
* Set includeMostRecentFullDay to false to count strictly before that day.
|
|
9388
9390
|
*
|
|
9389
9391
|
* @param options - Object with:
|
|
9390
9392
|
* - referenceDate: Date to count back from (default: now)
|
|
9391
|
-
* - days: Number of trading days to go back (must be >= 1)
|
|
9393
|
+
* - days: Number of trading days to go back (must be an integer >= 1)
|
|
9394
|
+
* - includeMostRecentFullDay: Whether to include the most recent completed trading day (default: true)
|
|
9392
9395
|
* @returns Object containing:
|
|
9393
9396
|
* - date: Trading date in YYYY-MM-DD format
|
|
9394
9397
|
* - marketOpenISO: Market open time as ISO string (e.g., "2025-11-15T13:30:00.000Z")
|
|
@@ -9410,13 +9413,17 @@ function countTradingDays(startDate, endDate = new Date()) {
|
|
|
9410
9413
|
*/
|
|
9411
9414
|
function getTradingDaysBack(options) {
|
|
9412
9415
|
const calendar = new MarketCalendar();
|
|
9413
|
-
const
|
|
9414
|
-
const
|
|
9415
|
-
|
|
9416
|
-
|
|
9416
|
+
const { referenceDate, days, includeMostRecentFullDay = true } = options;
|
|
9417
|
+
const refDate = referenceDate || new Date();
|
|
9418
|
+
const daysBack = days;
|
|
9419
|
+
if (!Number.isInteger(daysBack) || daysBack < 1) {
|
|
9420
|
+
throw new Error('days must be an integer >= 1');
|
|
9417
9421
|
}
|
|
9418
9422
|
// Start from the last full trading date relative to reference
|
|
9419
9423
|
let targetDate = getLastFullTradingDateImpl(refDate);
|
|
9424
|
+
if (!includeMostRecentFullDay) {
|
|
9425
|
+
targetDate = calendar.getPreviousMarketDay(targetDate);
|
|
9426
|
+
}
|
|
9420
9427
|
// Go back the specified number of days (we're already at day 1, so go back days-1 more)
|
|
9421
9428
|
for (let i = 1; i < daysBack; i++) {
|
|
9422
9429
|
targetDate = calendar.getPreviousMarketDay(targetDate);
|