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