@discomedia/utils 1.0.16 → 1.0.18
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-frontend.cjs +19 -32
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +19 -32
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +36 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +36 -36
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +3 -3
- package/dist/test.js +413 -7390
- package/dist/test.js.map +1 -1
- package/dist/types/market-time.d.ts +1 -1
- package/dist/types/market-time.d.ts.map +1 -1
- package/dist/types-frontend/market-time.d.ts +1 -1
- package/dist/types-frontend/market-time.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -386,16 +386,24 @@ class MarketTimeCalculator {
|
|
|
386
386
|
/**
|
|
387
387
|
* Get the last full trading date
|
|
388
388
|
*/
|
|
389
|
-
getLastFullTradingDate(currentDate = new Date()) {
|
|
389
|
+
getLastFullTradingDate(currentDate = new Date(), extendedHours = true) {
|
|
390
390
|
const nowET = toZonedTime(currentDate, this.timezone);
|
|
391
|
-
// If today is a market day and we're after extended hours close, return today
|
|
392
391
|
if (this.calendar.isMarketDay(nowET)) {
|
|
393
392
|
const timeInMinutes = nowET.getHours() * 60 + nowET.getMinutes();
|
|
394
|
-
let
|
|
395
|
-
if (
|
|
396
|
-
|
|
393
|
+
let endMinutes;
|
|
394
|
+
if (extendedHours) {
|
|
395
|
+
endMinutes = MARKET_CONFIG.TIMES.EXTENDED_END.hour * 60 + MARKET_CONFIG.TIMES.EXTENDED_END.minute;
|
|
396
|
+
if (this.calendar.isEarlyCloseDay(nowET)) {
|
|
397
|
+
endMinutes = MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.hour * 60 + MARKET_CONFIG.TIMES.EARLY_EXTENDED_END.minute;
|
|
398
|
+
}
|
|
397
399
|
}
|
|
398
|
-
|
|
400
|
+
else {
|
|
401
|
+
endMinutes = MARKET_CONFIG.TIMES.MARKET_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.MARKET_CLOSE.minute;
|
|
402
|
+
if (this.calendar.isEarlyCloseDay(nowET)) {
|
|
403
|
+
endMinutes = MARKET_CONFIG.TIMES.EARLY_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.EARLY_CLOSE.minute;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (timeInMinutes >= endMinutes) {
|
|
399
407
|
return fromZonedTime(set(nowET, { hours: 0, minutes: 0, seconds: 0, milliseconds: 0 }), this.timezone);
|
|
400
408
|
}
|
|
401
409
|
}
|
|
@@ -766,6 +774,12 @@ function getMarketStatus(options = {}) {
|
|
|
766
774
|
function isMarketDay(date) {
|
|
767
775
|
return marketCalendar.isMarketDay(date);
|
|
768
776
|
}
|
|
777
|
+
/**
|
|
778
|
+
* Check if a date is within market hours
|
|
779
|
+
*/
|
|
780
|
+
function isWithinMarketHours(date, intradayReporting = 'market_hours') {
|
|
781
|
+
return marketTimeCalculator.isWithinMarketHours(date, intradayReporting);
|
|
782
|
+
}
|
|
769
783
|
/**
|
|
770
784
|
* Function to find complete trading date periods, starting at the beginning of one trading date and ending at the last.
|
|
771
785
|
* By default, it gets the last trading date, returning the beginning and end. But we can also a) define the end date
|
|
@@ -778,9 +792,16 @@ function isMarketDay(date) {
|
|
|
778
792
|
function getTradingStartAndEndDates(options = {}) {
|
|
779
793
|
const { endDate = new Date(), days = 1 } = options;
|
|
780
794
|
// Get the last full trading date for the end date
|
|
781
|
-
|
|
782
|
-
//
|
|
783
|
-
|
|
795
|
+
let endTradingDate;
|
|
796
|
+
// If within market hours, on a trading day, use the current date as end
|
|
797
|
+
if (isWithinMarketHours(endDate, 'market_hours')) {
|
|
798
|
+
endTradingDate = endDate;
|
|
799
|
+
}
|
|
800
|
+
else {
|
|
801
|
+
// If after market hours, use the last full trading date, which should be the previous trading day, or after extended hours, the same trading day
|
|
802
|
+
const lastFullTradingDate = marketTimeCalculator.getLastFullTradingDate(endDate, false);
|
|
803
|
+
endTradingDate = getMarketOpenClose({ date: lastFullTradingDate }).close;
|
|
804
|
+
}
|
|
784
805
|
let startDate;
|
|
785
806
|
if (days <= 1) {
|
|
786
807
|
// For 1 day, start is market open of the same trading day as end
|
|
@@ -800,7 +821,7 @@ function getTradingStartAndEndDates(options = {}) {
|
|
|
800
821
|
// Get the market open time for the start date
|
|
801
822
|
startDate = getMarketOpenClose({ date: currentDate }).open;
|
|
802
823
|
}
|
|
803
|
-
return { startDate, endDate:
|
|
824
|
+
return { startDate, endDate: endTradingDate };
|
|
804
825
|
}
|
|
805
826
|
// Export the MARKET_TIMES constant for backward compatibility
|
|
806
827
|
const MARKET_TIMES = {
|
|
@@ -2258,7 +2279,7 @@ const safeJSON = (text) => {
|
|
|
2258
2279
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2259
2280
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
2260
2281
|
|
|
2261
|
-
const VERSION = '5.
|
|
2282
|
+
const VERSION = '5.10.1'; // x-release-please-version
|
|
2262
2283
|
|
|
2263
2284
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2264
2285
|
const isRunningInBrowser = () => {
|
|
@@ -3115,6 +3136,8 @@ class Stream {
|
|
|
3115
3136
|
}
|
|
3116
3137
|
if (sse.event === null ||
|
|
3117
3138
|
sse.event.startsWith('response.') ||
|
|
3139
|
+
sse.event.startsWith('image_edit.') ||
|
|
3140
|
+
sse.event.startsWith('image_generation.') ||
|
|
3118
3141
|
sse.event.startsWith('transcript.')) {
|
|
3119
3142
|
let data;
|
|
3120
3143
|
try {
|
|
@@ -7218,34 +7241,11 @@ class Images extends APIResource {
|
|
|
7218
7241
|
createVariation(body, options) {
|
|
7219
7242
|
return this._client.post('/images/variations', multipartFormRequestOptions({ body, ...options }, this._client));
|
|
7220
7243
|
}
|
|
7221
|
-
/**
|
|
7222
|
-
* Creates an edited or extended image given one or more source images and a
|
|
7223
|
-
* prompt. This endpoint only supports `gpt-image-1` and `dall-e-2`.
|
|
7224
|
-
*
|
|
7225
|
-
* @example
|
|
7226
|
-
* ```ts
|
|
7227
|
-
* const imagesResponse = await client.images.edit({
|
|
7228
|
-
* image: fs.createReadStream('path/to/file'),
|
|
7229
|
-
* prompt: 'A cute baby sea otter wearing a beret',
|
|
7230
|
-
* });
|
|
7231
|
-
* ```
|
|
7232
|
-
*/
|
|
7233
7244
|
edit(body, options) {
|
|
7234
|
-
return this._client.post('/images/edits', multipartFormRequestOptions({ body, ...options }, this._client));
|
|
7245
|
+
return this._client.post('/images/edits', multipartFormRequestOptions({ body, ...options, stream: body.stream ?? false }, this._client));
|
|
7235
7246
|
}
|
|
7236
|
-
/**
|
|
7237
|
-
* Creates an image given a prompt.
|
|
7238
|
-
* [Learn more](https://platform.openai.com/docs/guides/images).
|
|
7239
|
-
*
|
|
7240
|
-
* @example
|
|
7241
|
-
* ```ts
|
|
7242
|
-
* const imagesResponse = await client.images.generate({
|
|
7243
|
-
* prompt: 'A cute baby sea otter',
|
|
7244
|
-
* });
|
|
7245
|
-
* ```
|
|
7246
|
-
*/
|
|
7247
7247
|
generate(body, options) {
|
|
7248
|
-
return this._client.post('/images/generations', { body, ...options });
|
|
7248
|
+
return this._client.post('/images/generations', { body, ...options, stream: body.stream ?? false });
|
|
7249
7249
|
}
|
|
7250
7250
|
}
|
|
7251
7251
|
|