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