@discomedia/utils 1.0.17 → 1.0.19

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.
@@ -11,8 +11,6 @@ import require$$0$1 from 'buffer';
11
11
  import require$$0$4 from 'fs';
12
12
  import require$$1$1 from 'path';
13
13
  import require$$2$1 from 'os';
14
- import { startOfDay, set, endOfDay, add, sub } from 'date-fns';
15
- import { toZonedTime, fromZonedTime, formatInTimeZone } from 'date-fns-tz';
16
14
 
17
15
  var Types = /*#__PURE__*/Object.freeze({
18
16
  __proto__: null
@@ -249,7 +247,7 @@ const safeJSON = (text) => {
249
247
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
250
248
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
251
249
 
252
- const VERSION = '5.9.0'; // x-release-please-version
250
+ const VERSION = '5.10.1'; // x-release-please-version
253
251
 
254
252
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
255
253
  const isRunningInBrowser = () => {
@@ -1106,6 +1104,8 @@ class Stream {
1106
1104
  }
1107
1105
  if (sse.event === null ||
1108
1106
  sse.event.startsWith('response.') ||
1107
+ sse.event.startsWith('image_edit.') ||
1108
+ sse.event.startsWith('image_generation.') ||
1109
1109
  sse.event.startsWith('transcript.')) {
1110
1110
  let data;
1111
1111
  try {
@@ -5209,34 +5209,11 @@ class Images extends APIResource {
5209
5209
  createVariation(body, options) {
5210
5210
  return this._client.post('/images/variations', multipartFormRequestOptions({ body, ...options }, this._client));
5211
5211
  }
5212
- /**
5213
- * Creates an edited or extended image given one or more source images and a
5214
- * prompt. This endpoint only supports `gpt-image-1` and `dall-e-2`.
5215
- *
5216
- * @example
5217
- * ```ts
5218
- * const imagesResponse = await client.images.edit({
5219
- * image: fs.createReadStream('path/to/file'),
5220
- * prompt: 'A cute baby sea otter wearing a beret',
5221
- * });
5222
- * ```
5223
- */
5224
5212
  edit(body, options) {
5225
- return this._client.post('/images/edits', multipartFormRequestOptions({ body, ...options }, this._client));
5213
+ return this._client.post('/images/edits', multipartFormRequestOptions({ body, ...options, stream: body.stream ?? false }, this._client));
5226
5214
  }
5227
- /**
5228
- * Creates an image given a prompt.
5229
- * [Learn more](https://platform.openai.com/docs/guides/images).
5230
- *
5231
- * @example
5232
- * ```ts
5233
- * const imagesResponse = await client.images.generate({
5234
- * prompt: 'A cute baby sea otter',
5235
- * });
5236
- * ```
5237
- */
5238
5215
  generate(body, options) {
5239
- return this._client.post('/images/generations', { body, ...options });
5216
+ return this._client.post('/images/generations', { body, ...options, stream: body.stream ?? false });
5240
5217
  }
5241
5218
  }
5242
5219
 
@@ -13500,64 +13477,90 @@ const marketEarlyCloses = {
13500
13477
  },
13501
13478
  };
13502
13479
 
13503
- // market-time.ts - Refactored for better organization and usability
13504
- // ===== CONFIGURATION =====
13505
- /**
13506
- * Market configuration constants
13507
- */
13480
+ // Constants for NY market times (Eastern Time)
13508
13481
  const MARKET_CONFIG = {
13509
- TIMEZONE: 'America/New_York',
13482
+ UTC_OFFSET_STANDARD: -5, // EST
13483
+ UTC_OFFSET_DST: -4, // EDT
13510
13484
  TIMES: {
13511
- EXTENDED_START: { hour: 4, minute: 0 },
13512
13485
  MARKET_OPEN: { hour: 9, minute: 30 },
13513
13486
  MARKET_CLOSE: { hour: 16, minute: 0 },
13514
- EARLY_CLOSE: { hour: 13, minute: 0 },
13515
- EXTENDED_END: { hour: 20, minute: 0 },
13516
- EARLY_EXTENDED_END: { hour: 17, minute: 0 },
13517
- },
13487
+ EARLY_CLOSE: { hour: 13, minute: 0 }},
13518
13488
  };
13519
- // ===== MARKET CALENDAR SERVICE =====
13520
- /**
13521
- * Service for handling market calendar operations (holidays, early closes, market days)
13522
- */
13489
+ // Helper: Get NY offset for a given UTC date (DST rules for US)
13490
+ function getNYOffset(date) {
13491
+ // US DST starts 2nd Sunday in March, ends 1st Sunday in November
13492
+ const year = date.getUTCFullYear();
13493
+ const dstStart = getNthWeekdayOfMonth(year, 3, 0, 2); // March, Sunday, 2nd
13494
+ const dstEnd = getNthWeekdayOfMonth(year, 11, 0, 1); // November, Sunday, 1st
13495
+ const utcTime = date.getTime();
13496
+ if (utcTime >= dstStart.getTime() && utcTime < dstEnd.getTime()) {
13497
+ return MARKET_CONFIG.UTC_OFFSET_DST;
13498
+ }
13499
+ return MARKET_CONFIG.UTC_OFFSET_STANDARD;
13500
+ }
13501
+ // Helper: Get nth weekday of month in UTC
13502
+ function getNthWeekdayOfMonth(year, month, weekday, n) {
13503
+ let count = 0;
13504
+ for (let d = 1; d <= 31; d++) {
13505
+ const date = new Date(Date.UTC(year, month - 1, d));
13506
+ if (date.getUTCMonth() !== month - 1)
13507
+ break;
13508
+ if (date.getUTCDay() === weekday) {
13509
+ count++;
13510
+ if (count === n)
13511
+ return date;
13512
+ }
13513
+ }
13514
+ // fallback: last day of month
13515
+ return new Date(Date.UTC(year, month - 1, 28));
13516
+ }
13517
+ // Helper: Convert UTC date to NY time (returns new Date object)
13518
+ function toNYTime(date) {
13519
+ const offset = getNYOffset(date);
13520
+ // NY offset in hours
13521
+ const utcMillis = date.getTime();
13522
+ const nyMillis = utcMillis + offset * 60 * 60 * 1000;
13523
+ return new Date(nyMillis);
13524
+ }
13525
+ // Helper: Convert NY time to UTC (returns new Date object)
13526
+ function fromNYTime(date) {
13527
+ const offset = getNYOffset(date);
13528
+ const nyMillis = date.getTime();
13529
+ const utcMillis = nyMillis - offset * 60 * 60 * 1000;
13530
+ return new Date(utcMillis);
13531
+ }
13532
+ // Market calendar logic
13523
13533
  class MarketCalendar {
13524
- timezone;
13525
- constructor(timezone = MARKET_CONFIG.TIMEZONE) {
13526
- this.timezone = timezone;
13527
- }
13528
- /**
13529
- * Check if a date is a weekend
13530
- */
13531
13534
  isWeekend(date) {
13532
- const day = date.getDay();
13533
- return day === 0 || day === 6; // Sunday or Saturday
13535
+ const day = toNYTime(date).getUTCDay();
13536
+ return day === 0 || day === 6;
13534
13537
  }
13535
- /**
13536
- * Check if a date is a market holiday
13537
- */
13538
13538
  isHoliday(date) {
13539
- const formattedDate = formatInTimeZone(date, this.timezone, 'yyyy-MM-dd');
13540
- const year = toZonedTime(date, this.timezone).getFullYear();
13539
+ const nyDate = toNYTime(date);
13540
+ const year = nyDate.getUTCFullYear();
13541
+ const month = nyDate.getUTCMonth() + 1;
13542
+ const day = nyDate.getUTCDate();
13543
+ const formattedDate = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
13541
13544
  const yearHolidays = marketHolidays[year];
13542
13545
  if (!yearHolidays)
13543
13546
  return false;
13544
13547
  return Object.values(yearHolidays).some(holiday => holiday.date === formattedDate);
13545
13548
  }
13546
- /**
13547
- * Check if a date is an early close day
13548
- */
13549
13549
  isEarlyCloseDay(date) {
13550
- const formattedDate = formatInTimeZone(date, this.timezone, 'yyyy-MM-dd');
13551
- const year = toZonedTime(date, this.timezone).getFullYear();
13550
+ const nyDate = toNYTime(date);
13551
+ const year = nyDate.getUTCFullYear();
13552
+ const month = nyDate.getUTCMonth() + 1;
13553
+ const day = nyDate.getUTCDate();
13554
+ const formattedDate = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
13552
13555
  const yearEarlyCloses = marketEarlyCloses[year];
13553
13556
  return yearEarlyCloses && yearEarlyCloses[formattedDate] !== undefined;
13554
13557
  }
13555
- /**
13556
- * Get the early close time for a date (in minutes from midnight)
13557
- */
13558
13558
  getEarlyCloseTime(date) {
13559
- const formattedDate = formatInTimeZone(date, this.timezone, 'yyyy-MM-dd');
13560
- const year = toZonedTime(date, this.timezone).getFullYear();
13559
+ const nyDate = toNYTime(date);
13560
+ const year = nyDate.getUTCFullYear();
13561
+ const month = nyDate.getUTCMonth() + 1;
13562
+ const day = nyDate.getUTCDate();
13563
+ const formattedDate = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
13561
13564
  const yearEarlyCloses = marketEarlyCloses[year];
13562
13565
  if (yearEarlyCloses && yearEarlyCloses[formattedDate]) {
13563
13566
  const [hours, minutes] = yearEarlyCloses[formattedDate].time.split(':').map(Number);
@@ -13565,285 +13568,61 @@ class MarketCalendar {
13565
13568
  }
13566
13569
  return null;
13567
13570
  }
13568
- /**
13569
- * Check if a date is a market day (not weekend or holiday)
13570
- */
13571
13571
  isMarketDay(date) {
13572
13572
  return !this.isWeekend(date) && !this.isHoliday(date);
13573
13573
  }
13574
- /**
13575
- * Get the next market day from a given date
13576
- */
13577
13574
  getNextMarketDay(date) {
13578
- let nextDay = add(date, { days: 1 });
13575
+ let nextDay = new Date(date.getTime() + 24 * 60 * 60 * 1000);
13579
13576
  while (!this.isMarketDay(nextDay)) {
13580
- nextDay = add(nextDay, { days: 1 });
13577
+ nextDay = new Date(nextDay.getTime() + 24 * 60 * 60 * 1000);
13581
13578
  }
13582
13579
  return nextDay;
13583
13580
  }
13584
- /**
13585
- * Get the previous market day from a given date
13586
- */
13587
13581
  getPreviousMarketDay(date) {
13588
- let prevDay = sub(date, { days: 1 });
13582
+ let prevDay = new Date(date.getTime() - 24 * 60 * 60 * 1000);
13589
13583
  while (!this.isMarketDay(prevDay)) {
13590
- prevDay = sub(prevDay, { days: 1 });
13584
+ prevDay = new Date(prevDay.getTime() - 24 * 60 * 60 * 1000);
13591
13585
  }
13592
13586
  return prevDay;
13593
13587
  }
13594
13588
  }
13595
- // ===== TIME FORMATTER SERVICE =====
13596
- /**
13597
- * Service for formatting time outputs
13598
- */
13599
- class TimeFormatter {
13600
- timezone;
13601
- constructor(timezone = MARKET_CONFIG.TIMEZONE) {
13602
- this.timezone = timezone;
13603
- }
13604
- /**
13605
- * Format a date based on the output format
13606
- */
13607
- formatDate(date, outputFormat = 'iso') {
13608
- switch (outputFormat) {
13609
- case 'unix-seconds':
13610
- return Math.floor(date.getTime() / 1000);
13611
- case 'unix-ms':
13612
- return date.getTime();
13613
- case 'iso':
13614
- default:
13615
- return formatInTimeZone(date, this.timezone, "yyyy-MM-dd'T'HH:mm:ssXXX");
13616
- }
13617
- }
13618
- /**
13619
- * Get New York timezone offset
13620
- */
13621
- getNYTimeZone(date = new Date()) {
13622
- const dtf = new Intl.DateTimeFormat('en-US', {
13623
- timeZone: this.timezone,
13624
- timeZoneName: 'shortOffset',
13625
- });
13626
- const parts = dtf.formatToParts(date);
13627
- const tz = parts.find(p => p.type === 'timeZoneName')?.value;
13628
- if (!tz) {
13629
- throw new Error('Could not determine New York offset');
13630
- }
13631
- const shortOffset = tz.replace('GMT', '');
13632
- if (shortOffset === '-4') {
13633
- return '-04:00';
13634
- }
13635
- else if (shortOffset === '-5') {
13636
- return '-05:00';
13637
- }
13638
- else {
13639
- throw new Error(`Unexpected timezone offset: ${shortOffset}`);
13640
- }
13641
- }
13642
- /**
13643
- * Get trading date in YYYY-MM-DD format
13644
- */
13645
- getTradingDate(time) {
13646
- let date;
13647
- if (typeof time === 'number') {
13648
- date = new Date(time);
13649
- }
13650
- else if (typeof time === 'string') {
13651
- date = new Date(time);
13652
- }
13653
- else {
13654
- date = time;
13655
- }
13656
- return formatInTimeZone(date, this.timezone, 'yyyy-MM-dd');
13657
- }
13589
+ // Get last full trading date
13590
+ function getLastFullTradingDateImpl(currentDate = new Date()) {
13591
+ const calendar = new MarketCalendar();
13592
+ const nyDate = toNYTime(currentDate);
13593
+ const minutes = nyDate.getUTCHours() * 60 + nyDate.getUTCMinutes();
13594
+ const marketOpenMinutes = MARKET_CONFIG.TIMES.MARKET_OPEN.hour * 60 + MARKET_CONFIG.TIMES.MARKET_OPEN.minute;
13595
+ let marketCloseMinutes = MARKET_CONFIG.TIMES.MARKET_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.MARKET_CLOSE.minute;
13596
+ if (calendar.isEarlyCloseDay(currentDate)) {
13597
+ marketCloseMinutes = MARKET_CONFIG.TIMES.EARLY_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.EARLY_CLOSE.minute;
13598
+ }
13599
+ // If not a market day, or before open, or during market hours, return previous market day's close
13600
+ if (!calendar.isMarketDay(currentDate) || minutes < marketOpenMinutes || (minutes >= marketOpenMinutes && minutes < marketCloseMinutes)) {
13601
+ const prevMarketDay = calendar.getPreviousMarketDay(currentDate);
13602
+ let prevCloseMinutes = MARKET_CONFIG.TIMES.MARKET_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.MARKET_CLOSE.minute;
13603
+ if (calendar.isEarlyCloseDay(prevMarketDay)) {
13604
+ prevCloseMinutes = MARKET_CONFIG.TIMES.EARLY_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.EARLY_CLOSE.minute;
13605
+ }
13606
+ const year = prevMarketDay.getUTCFullYear();
13607
+ const month = prevMarketDay.getUTCMonth();
13608
+ const day = prevMarketDay.getUTCDate();
13609
+ const closeHour = Math.floor(prevCloseMinutes / 60);
13610
+ const closeMinute = prevCloseMinutes % 60;
13611
+ return fromNYTime(new Date(Date.UTC(year, month, day, closeHour, closeMinute, 0, 0)));
13612
+ }
13613
+ // After market close or after extended hours, return today's close
13614
+ const year = nyDate.getUTCFullYear();
13615
+ const month = nyDate.getUTCMonth();
13616
+ const day = nyDate.getUTCDate();
13617
+ const closeHour = Math.floor(marketCloseMinutes / 60);
13618
+ const closeMinute = marketCloseMinutes % 60;
13619
+ return fromNYTime(new Date(Date.UTC(year, month, day, closeHour, closeMinute, 0, 0)));
13658
13620
  }
13659
- // ===== MARKET TIME CALCULATOR =====
13660
13621
  /**
13661
- * Service for core market time calculations
13662
- */
13663
- class MarketTimeCalculator {
13664
- calendar;
13665
- timezone;
13666
- constructor(timezone = MARKET_CONFIG.TIMEZONE) {
13667
- this.timezone = timezone;
13668
- this.calendar = new MarketCalendar(timezone);
13669
- }
13670
- /**
13671
- * Get market open/close times for a date
13672
- */
13673
- getMarketTimes(date) {
13674
- const zonedDate = toZonedTime(date, this.timezone);
13675
- // Market closed on weekends and holidays
13676
- if (!this.calendar.isMarketDay(zonedDate)) {
13677
- return {
13678
- marketOpen: false,
13679
- open: null,
13680
- close: null,
13681
- openExt: null,
13682
- closeExt: null,
13683
- };
13684
- }
13685
- const dayStart = startOfDay(zonedDate);
13686
- // Regular market times
13687
- const open = fromZonedTime(set(dayStart, { hours: MARKET_CONFIG.TIMES.MARKET_OPEN.hour, minutes: MARKET_CONFIG.TIMES.MARKET_OPEN.minute }), this.timezone);
13688
- let close = fromZonedTime(set(dayStart, { hours: MARKET_CONFIG.TIMES.MARKET_CLOSE.hour, minutes: MARKET_CONFIG.TIMES.MARKET_CLOSE.minute }), this.timezone);
13689
- // Extended hours
13690
- const openExt = fromZonedTime(set(dayStart, { hours: MARKET_CONFIG.TIMES.EXTENDED_START.hour, minutes: MARKET_CONFIG.TIMES.EXTENDED_START.minute }), this.timezone);
13691
- let closeExt = fromZonedTime(set(dayStart, { hours: MARKET_CONFIG.TIMES.EXTENDED_END.hour, minutes: MARKET_CONFIG.TIMES.EXTENDED_END.minute }), this.timezone);
13692
- // Handle early close days
13693
- if (this.calendar.isEarlyCloseDay(zonedDate)) {
13694
- close = fromZonedTime(set(dayStart, { hours: MARKET_CONFIG.TIMES.EARLY_CLOSE.hour, minutes: MARKET_CONFIG.TIMES.EARLY_CLOSE.minute }), this.timezone);
13695
- closeExt = fromZonedTime(set(dayStart, { hours: MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.hour, minutes: MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.minute }), this.timezone);
13696
- }
13697
- return {
13698
- marketOpen: true,
13699
- open,
13700
- close,
13701
- openExt,
13702
- closeExt,
13703
- };
13704
- }
13705
- /**
13706
- * Check if a time is within market hours based on intraday reporting mode
13707
- */
13708
- isWithinMarketHours(date, intradayReporting = 'market_hours') {
13709
- const zonedDate = toZonedTime(date, this.timezone);
13710
- // Not a market day
13711
- if (!this.calendar.isMarketDay(zonedDate)) {
13712
- return false;
13713
- }
13714
- const timeInMinutes = zonedDate.getHours() * 60 + zonedDate.getMinutes();
13715
- switch (intradayReporting) {
13716
- case 'extended_hours': {
13717
- const startMinutes = MARKET_CONFIG.TIMES.EXTENDED_START.hour * 60 + MARKET_CONFIG.TIMES.EXTENDED_START.minute;
13718
- let endMinutes = MARKET_CONFIG.TIMES.EXTENDED_END.hour * 60 + MARKET_CONFIG.TIMES.EXTENDED_END.minute;
13719
- // Handle early close
13720
- if (this.calendar.isEarlyCloseDay(zonedDate)) {
13721
- endMinutes = MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.hour * 60 + MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.minute;
13722
- }
13723
- return timeInMinutes >= startMinutes && timeInMinutes <= endMinutes;
13724
- }
13725
- case 'continuous':
13726
- return true;
13727
- default: {
13728
- // 'market_hours'
13729
- const startMinutes = MARKET_CONFIG.TIMES.MARKET_OPEN.hour * 60 + MARKET_CONFIG.TIMES.MARKET_OPEN.minute;
13730
- let endMinutes = MARKET_CONFIG.TIMES.MARKET_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.MARKET_CLOSE.minute;
13731
- // Handle early close
13732
- if (this.calendar.isEarlyCloseDay(zonedDate)) {
13733
- endMinutes = MARKET_CONFIG.TIMES.EARLY_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.EARLY_CLOSE.minute;
13734
- }
13735
- return timeInMinutes >= startMinutes && timeInMinutes <= endMinutes;
13736
- }
13737
- }
13738
- }
13739
- /**
13740
- * Get the last full trading date
13741
- */
13742
- getLastFullTradingDate(currentDate = new Date(), extendedHours = true) {
13743
- const nowET = toZonedTime(currentDate, this.timezone);
13744
- if (this.calendar.isMarketDay(nowET)) {
13745
- const timeInMinutes = nowET.getHours() * 60 + nowET.getMinutes();
13746
- let endMinutes;
13747
- if (extendedHours) {
13748
- endMinutes = MARKET_CONFIG.TIMES.EXTENDED_END.hour * 60 + MARKET_CONFIG.TIMES.EXTENDED_END.minute;
13749
- if (this.calendar.isEarlyCloseDay(nowET)) {
13750
- endMinutes = MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.hour * 60 + MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.minute;
13751
- }
13752
- }
13753
- else {
13754
- endMinutes = MARKET_CONFIG.TIMES.MARKET_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.MARKET_CLOSE.minute;
13755
- if (this.calendar.isEarlyCloseDay(nowET)) {
13756
- endMinutes = MARKET_CONFIG.TIMES.EARLY_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.EARLY_CLOSE.minute;
13757
- }
13758
- }
13759
- if (timeInMinutes >= endMinutes) {
13760
- return fromZonedTime(set(nowET, { hours: 0, minutes: 0, seconds: 0, milliseconds: 0 }), this.timezone);
13761
- }
13762
- }
13763
- // Return the last completed trading day
13764
- const lastMarketDay = this.calendar.getPreviousMarketDay(nowET);
13765
- return fromZonedTime(set(lastMarketDay, { hours: 0, minutes: 0, seconds: 0, milliseconds: 0 }), this.timezone);
13766
- }
13767
- /**
13768
- * Get day boundaries based on intraday reporting mode
13769
- */
13770
- getDayBoundaries(date, intradayReporting = 'market_hours') {
13771
- const zonedDate = toZonedTime(date, this.timezone);
13772
- let start;
13773
- let end;
13774
- switch (intradayReporting) {
13775
- case 'extended_hours': {
13776
- start = set(zonedDate, {
13777
- hours: MARKET_CONFIG.TIMES.EXTENDED_START.hour,
13778
- minutes: MARKET_CONFIG.TIMES.EXTENDED_START.minute,
13779
- seconds: 0,
13780
- milliseconds: 0,
13781
- });
13782
- end = set(zonedDate, {
13783
- hours: MARKET_CONFIG.TIMES.EXTENDED_END.hour,
13784
- minutes: MARKET_CONFIG.TIMES.EXTENDED_END.minute,
13785
- seconds: 59,
13786
- milliseconds: 999,
13787
- });
13788
- // Handle early close
13789
- if (this.calendar.isEarlyCloseDay(zonedDate)) {
13790
- end = set(zonedDate, {
13791
- hours: MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.hour,
13792
- minutes: MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.minute,
13793
- seconds: 59,
13794
- milliseconds: 999,
13795
- });
13796
- }
13797
- break;
13798
- }
13799
- case 'continuous': {
13800
- start = startOfDay(zonedDate);
13801
- end = endOfDay(zonedDate);
13802
- break;
13803
- }
13804
- default: {
13805
- // 'market_hours'
13806
- start = set(zonedDate, {
13807
- hours: MARKET_CONFIG.TIMES.MARKET_OPEN.hour,
13808
- minutes: MARKET_CONFIG.TIMES.MARKET_OPEN.minute,
13809
- seconds: 0,
13810
- milliseconds: 0,
13811
- });
13812
- end = set(zonedDate, {
13813
- hours: MARKET_CONFIG.TIMES.MARKET_CLOSE.hour,
13814
- minutes: MARKET_CONFIG.TIMES.MARKET_CLOSE.minute,
13815
- seconds: 59,
13816
- milliseconds: 999,
13817
- });
13818
- // Handle early close
13819
- if (this.calendar.isEarlyCloseDay(zonedDate)) {
13820
- end = set(zonedDate, {
13821
- hours: MARKET_CONFIG.TIMES.EARLY_CLOSE.hour,
13822
- minutes: MARKET_CONFIG.TIMES.EARLY_CLOSE.minute,
13823
- seconds: 59,
13824
- milliseconds: 999,
13825
- });
13826
- }
13827
- break;
13828
- }
13829
- }
13830
- return {
13831
- start: fromZonedTime(start, this.timezone),
13832
- end: fromZonedTime(end, this.timezone),
13833
- };
13834
- }
13835
- }
13836
- const marketTimeCalculator = new MarketTimeCalculator();
13837
- const timeFormatter = new TimeFormatter();
13838
- /**
13839
- * Get the last full trading date
13622
+ * Returns the last full trading date as a Date object.
13840
13623
  */
13841
13624
  function getLastFullTradingDate(currentDate = new Date()) {
13842
- const date = marketTimeCalculator.getLastFullTradingDate(currentDate);
13843
- return {
13844
- date,
13845
- YYYYMMDD: timeFormatter.getTradingDate(date),
13846
- };
13625
+ return getLastFullTradingDateImpl(currentDate);
13847
13626
  }
13848
13627
 
13849
13628
  const log = (message, options = { type: 'info' }) => {
@@ -14243,8 +14022,8 @@ class AlpacaMarketDataAPI extends EventEmitter {
14243
14022
  const response = await this.getHistoricalBars({
14244
14023
  symbols: [symbol],
14245
14024
  timeframe: '1Day',
14246
- start: prevMarketDate.date.toISOString(),
14247
- end: prevMarketDate.date.toISOString(),
14025
+ start: prevMarketDate.toISOString(),
14026
+ end: prevMarketDate.toISOString(),
14248
14027
  limit: 1,
14249
14028
  });
14250
14029
  if (!response.bars[symbol] || response.bars[symbol].length === 0) {