@discomedia/utils 1.0.16 → 1.0.17

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.
@@ -13741,16 +13741,24 @@ class MarketTimeCalculator {
13741
13741
  /**
13742
13742
  * Get the last full trading date
13743
13743
  */
13744
- getLastFullTradingDate(currentDate = new Date()) {
13744
+ getLastFullTradingDate(currentDate = new Date(), extendedHours = true) {
13745
13745
  const nowET = dateFnsTz.toZonedTime(currentDate, this.timezone);
13746
- // If today is a market day and we're after extended hours close, return today
13747
13746
  if (this.calendar.isMarketDay(nowET)) {
13748
13747
  const timeInMinutes = nowET.getHours() * 60 + nowET.getMinutes();
13749
- let extendedEndMinutes = MARKET_CONFIG.TIMES.EXTENDED_END.hour * 60 + MARKET_CONFIG.TIMES.EXTENDED_END.minute;
13750
- if (this.calendar.isEarlyCloseDay(nowET)) {
13751
- extendedEndMinutes = MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.hour * 60 + MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.minute;
13748
+ let endMinutes;
13749
+ if (extendedHours) {
13750
+ endMinutes = MARKET_CONFIG.TIMES.EXTENDED_END.hour * 60 + MARKET_CONFIG.TIMES.EXTENDED_END.minute;
13751
+ if (this.calendar.isEarlyCloseDay(nowET)) {
13752
+ endMinutes = MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.hour * 60 + MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.minute;
13753
+ }
13754
+ }
13755
+ else {
13756
+ endMinutes = MARKET_CONFIG.TIMES.MARKET_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.MARKET_CLOSE.minute;
13757
+ if (this.calendar.isEarlyCloseDay(nowET)) {
13758
+ endMinutes = MARKET_CONFIG.TIMES.EARLY_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.EARLY_CLOSE.minute;
13759
+ }
13752
13760
  }
13753
- if (timeInMinutes >= extendedEndMinutes) {
13761
+ if (timeInMinutes >= endMinutes) {
13754
13762
  return dateFnsTz.fromZonedTime(dateFns.set(nowET, { hours: 0, minutes: 0, seconds: 0, milliseconds: 0 }), this.timezone);
13755
13763
  }
13756
13764
  }