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