@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.cjs
CHANGED
|
@@ -969,10 +969,13 @@ function countTradingDays(startDate, endDate = new Date()) {
|
|
|
969
969
|
/**
|
|
970
970
|
* Returns the trading day N days back from a reference date, along with its market open time.
|
|
971
971
|
* Trading days are counted as full or half trading days (days that end count as 1 full trading day).
|
|
972
|
+
* By default, the most recent completed trading day counts as day 1.
|
|
973
|
+
* Set includeMostRecentFullDay to false to count strictly before that day.
|
|
972
974
|
*
|
|
973
975
|
* @param options - Object with:
|
|
974
976
|
* - referenceDate: Date to count back from (default: now)
|
|
975
|
-
* - days: Number of trading days to go back (must be >= 1)
|
|
977
|
+
* - days: Number of trading days to go back (must be an integer >= 1)
|
|
978
|
+
* - includeMostRecentFullDay: Whether to include the most recent completed trading day (default: true)
|
|
976
979
|
* @returns Object containing:
|
|
977
980
|
* - date: Trading date in YYYY-MM-DD format
|
|
978
981
|
* - marketOpenISO: Market open time as ISO string (e.g., "2025-11-15T13:30:00.000Z")
|
|
@@ -994,13 +997,17 @@ function countTradingDays(startDate, endDate = new Date()) {
|
|
|
994
997
|
*/
|
|
995
998
|
function getTradingDaysBack(options) {
|
|
996
999
|
const calendar = new MarketCalendar();
|
|
997
|
-
const
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
|
|
1000
|
+
const { referenceDate, days, includeMostRecentFullDay = true } = options;
|
|
1001
|
+
const refDate = referenceDate || new Date();
|
|
1002
|
+
const daysBack = days;
|
|
1003
|
+
if (!Number.isInteger(daysBack) || daysBack < 1) {
|
|
1004
|
+
throw new Error('days must be an integer >= 1');
|
|
1001
1005
|
}
|
|
1002
1006
|
// Start from the last full trading date relative to reference
|
|
1003
1007
|
let targetDate = getLastFullTradingDateImpl(refDate);
|
|
1008
|
+
if (!includeMostRecentFullDay) {
|
|
1009
|
+
targetDate = calendar.getPreviousMarketDay(targetDate);
|
|
1010
|
+
}
|
|
1004
1011
|
// Go back the specified number of days (we're already at day 1, so go back days-1 more)
|
|
1005
1012
|
for (let i = 1; i < daysBack; i++) {
|
|
1006
1013
|
targetDate = calendar.getPreviousMarketDay(targetDate);
|