@discomedia/utils 1.0.51 → 1.0.53

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