@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.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 refDate = options.referenceDate || new Date();
998
- const daysBack = options.days;
999
- if (daysBack < 1) {
1000
- throw new Error('days must be at least 1');
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);