@discomedia/utils 1.0.19 → 1.0.20
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/README.md +5 -0
- package/dist/index-frontend.cjs +78 -4
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +78 -4
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +240 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +240 -4
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +5 -9
- package/dist/test.js +5787 -1025
- package/dist/test.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/market-time.d.ts +97 -0
- package/dist/types/market-time.d.ts.map +1 -1
- package/dist/types-frontend/index.d.ts +1 -0
- package/dist/types-frontend/index.d.ts.map +1 -1
- package/dist/types-frontend/market-time.d.ts +97 -0
- package/dist/types-frontend/market-time.d.ts.map +1 -1
- package/package.json +5 -9
package/dist/types/index.d.ts
CHANGED
|
@@ -116,6 +116,7 @@ export declare const disco: {
|
|
|
116
116
|
getNYTimeZone: typeof mt.getNYTimeZone;
|
|
117
117
|
getTradingDate: typeof mt.getTradingDate;
|
|
118
118
|
getTradingStartAndEndDates: typeof mt.getTradingStartAndEndDates;
|
|
119
|
+
countTradingDays: typeof mt.countTradingDays;
|
|
119
120
|
MARKET_TIMES: Types.MarketTimesConfig;
|
|
120
121
|
};
|
|
121
122
|
utils: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;A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AC;sBAAyB,CAAC;;;kBAAhxP,CAAC;;;kBAAwjc,CAAC;qBAAuB,CAAC;uBAAkC,CAAC;wBAAmC,CAAC;uBAAkC,CAAC;wBAAmC,CAAC;iBAA4B,CAAC;iBAA2B,CAAC;gBAAkB,CAAC;;;;;eAA5/W,CAAC;;;iBAAiE,CAAC;;kBAAmC,CAAC;;;;;kBAA65Q,CAAC;oBAAsB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADnxZ,CAAC"}
|
|
@@ -34,9 +34,19 @@ export declare const MARKET_CONFIG: {
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Returns market open/close times for a given date.
|
|
39
|
+
* @param options - { date?: Date }
|
|
40
|
+
* @returns MarketOpenCloseResult
|
|
41
|
+
*/
|
|
37
42
|
export declare function getMarketOpenClose(options?: {
|
|
38
43
|
date?: Date;
|
|
39
44
|
}): MarketOpenCloseResult;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the start and end dates for a market time period as Date objects.
|
|
47
|
+
* @param params - MarketTimeParams
|
|
48
|
+
* @returns Object with start and end Date
|
|
49
|
+
*/
|
|
40
50
|
export declare function getStartAndEndDates(params?: MarketTimeParams): {
|
|
41
51
|
start: Date;
|
|
42
52
|
end: Date;
|
|
@@ -44,14 +54,29 @@ export declare function getStartAndEndDates(params?: MarketTimeParams): {
|
|
|
44
54
|
/**
|
|
45
55
|
* Returns the last full trading date as a Date object.
|
|
46
56
|
*/
|
|
57
|
+
/**
|
|
58
|
+
* Returns the last full trading date as a Date object.
|
|
59
|
+
* @param currentDate - Date object (default: now)
|
|
60
|
+
* @returns Date object for last full trading date
|
|
61
|
+
*/
|
|
47
62
|
export declare function getLastFullTradingDate(currentDate?: Date): Date;
|
|
48
63
|
/**
|
|
49
64
|
* Returns the last full trading date and formatted YYYYMMDD string.
|
|
50
65
|
*/
|
|
66
|
+
/**
|
|
67
|
+
* Returns the last full trading date and formatted YYYY-MM-DD string.
|
|
68
|
+
* @param currentDate - Date object (default: now)
|
|
69
|
+
* @returns Object with date and YYYYMMDD string
|
|
70
|
+
*/
|
|
51
71
|
export declare function getLastFullTradingDateInfo(currentDate?: Date): {
|
|
52
72
|
date: Date;
|
|
53
73
|
YYYYMMDD: string;
|
|
54
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Returns the next market day after the reference date.
|
|
77
|
+
* @param referenceDate - Date object (default: now)
|
|
78
|
+
* @returns Object with date, yyyymmdd string, and ISO string
|
|
79
|
+
*/
|
|
55
80
|
export declare function getNextMarketDay({ referenceDate }?: {
|
|
56
81
|
referenceDate?: Date;
|
|
57
82
|
}): {
|
|
@@ -64,18 +89,49 @@ export declare function getNextMarketDay({ referenceDate }?: {
|
|
|
64
89
|
* @param time - a string, number (unix timestamp), or Date object representing the time
|
|
65
90
|
* @returns the trading date as a string in YYYY-MM-DD format
|
|
66
91
|
*/
|
|
92
|
+
/**
|
|
93
|
+
* Returns the trading date for a given time in YYYY-MM-DD format (NY time).
|
|
94
|
+
* @param time - string, number, or Date
|
|
95
|
+
* @returns trading date string
|
|
96
|
+
*/
|
|
67
97
|
export declare function getTradingDate(time: string | number | Date): string;
|
|
98
|
+
/**
|
|
99
|
+
* Returns the NY timezone offset string for a given date.
|
|
100
|
+
* @param date - Date object (default: now)
|
|
101
|
+
* @returns '-04:00' for EDT, '-05:00' for EST
|
|
102
|
+
*/
|
|
68
103
|
export declare function getNYTimeZone(date?: Date): '-04:00' | '-05:00';
|
|
104
|
+
/**
|
|
105
|
+
* Returns the current market status for a given date.
|
|
106
|
+
* @param options - { date?: Date }
|
|
107
|
+
* @returns MarketStatus object
|
|
108
|
+
*/
|
|
69
109
|
export declare function getMarketStatus(options?: {
|
|
70
110
|
date?: Date;
|
|
71
111
|
}): MarketStatus;
|
|
112
|
+
/**
|
|
113
|
+
* Checks if a date is a market day.
|
|
114
|
+
* @param date - Date object
|
|
115
|
+
* @returns true if market day, false otherwise
|
|
116
|
+
*/
|
|
72
117
|
export declare function isMarketDay(date: Date): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Checks if a date/time is within market hours, extended hours, or continuous.
|
|
120
|
+
* @param date - Date object
|
|
121
|
+
* @param intradayReporting - 'market_hours', 'extended_hours', or 'continuous'
|
|
122
|
+
* @returns true if within hours, false otherwise
|
|
123
|
+
*/
|
|
73
124
|
export declare function isWithinMarketHours(date: Date, intradayReporting?: IntradayReporting): boolean;
|
|
74
125
|
/**
|
|
75
126
|
* Returns full trading days from market open to market close.
|
|
76
127
|
* endDate is always the most recent market close (previous day's close if before open, today's close if after open).
|
|
77
128
|
* days: 1 or not specified = that day's open; 2 = previous market day's open, etc.
|
|
78
129
|
*/
|
|
130
|
+
/**
|
|
131
|
+
* Returns full trading days from market open to market close.
|
|
132
|
+
* @param options - { endDate?: Date, days?: number }
|
|
133
|
+
* @returns Object with startDate and endDate
|
|
134
|
+
*/
|
|
79
135
|
export declare function getTradingStartAndEndDates(options?: {
|
|
80
136
|
endDate?: Date;
|
|
81
137
|
days?: number;
|
|
@@ -83,6 +139,12 @@ export declare function getTradingStartAndEndDates(options?: {
|
|
|
83
139
|
startDate: Date;
|
|
84
140
|
endDate: Date;
|
|
85
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* Creates a MarketTime utility instance with helper methods.
|
|
144
|
+
* @param timezone - Optional timezone string
|
|
145
|
+
* @param intradayReporting - Optional intraday reporting mode
|
|
146
|
+
* @returns Utility object with market time methods
|
|
147
|
+
*/
|
|
86
148
|
export declare function createMarketTimeUtil(timezone?: string, intradayReporting?: IntradayReporting): {
|
|
87
149
|
isMarketDay: (date: Date) => boolean;
|
|
88
150
|
isWithinMarketHours: (date: Date) => boolean;
|
|
@@ -96,6 +158,9 @@ export declare function createMarketTimeUtil(timezone?: string, intradayReportin
|
|
|
96
158
|
isEarlyCloseDay: (date: Date) => boolean;
|
|
97
159
|
getEarlyCloseTime: (date: Date) => number | null;
|
|
98
160
|
};
|
|
161
|
+
/**
|
|
162
|
+
* Backward compatibility class for MarketTime utilities.
|
|
163
|
+
*/
|
|
99
164
|
export declare class MarketTimeUtil {
|
|
100
165
|
private intradayReporting;
|
|
101
166
|
constructor(timezone?: string, intradayReporting?: IntradayReporting);
|
|
@@ -110,5 +175,37 @@ export declare class MarketTimeUtil {
|
|
|
110
175
|
isEarlyCloseDay(date: Date): boolean;
|
|
111
176
|
getEarlyCloseTime(date: Date): number | null;
|
|
112
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Counts trading time between two dates (passed as standard Date objects), excluding weekends and holidays, and closed market hours, using other functions in this library.
|
|
180
|
+
*
|
|
181
|
+
* This function calculates the actual trading time between two dates by:
|
|
182
|
+
* 1. Iterating through each calendar day between startDate and endDate (inclusive)
|
|
183
|
+
* 2. For each day that is a market day (not weekend/holiday), getting market open/close times
|
|
184
|
+
* 3. Calculating the overlap between the time range and market hours for that day
|
|
185
|
+
* 4. Summing up all the trading minutes across all days
|
|
186
|
+
*
|
|
187
|
+
* The function automatically handles:
|
|
188
|
+
* - Weekends (Saturday/Sunday) - skipped entirely
|
|
189
|
+
* - Market holidays - skipped entirely
|
|
190
|
+
* - Early close days (e.g. day before holidays) - uses early close time
|
|
191
|
+
* - Times outside market hours - only counts time within 9:30am-4pm ET (or early close)
|
|
192
|
+
*
|
|
193
|
+
* Examples:
|
|
194
|
+
* - 12pm to 3:30pm same day = 3.5 hours = 210 minutes = 0.54 days
|
|
195
|
+
* - 9:30am to 4pm same day = 6.5 hours = 390 minutes = 1 day
|
|
196
|
+
* - Friday 2pm to Monday 2pm = 6.5 hours (Friday 2pm-4pm + Monday 9:30am-2pm)
|
|
197
|
+
*
|
|
198
|
+
* @param startDate - Start date/time
|
|
199
|
+
* @param endDate - End date/time (default: now)
|
|
200
|
+
* @returns Object containing:
|
|
201
|
+
* - days: Trading time as fraction of full trading days (6.5 hours = 1 day)
|
|
202
|
+
* - hours: Trading time in hours
|
|
203
|
+
* - minutes: Trading time in minutes
|
|
204
|
+
*/
|
|
205
|
+
export declare function countTradingDays(startDate: Date, endDate?: Date): {
|
|
206
|
+
days: number;
|
|
207
|
+
hours: number;
|
|
208
|
+
minutes: number;
|
|
209
|
+
};
|
|
113
210
|
export declare const MARKET_TIMES: MarketTimesConfig;
|
|
114
211
|
//# sourceMappingURL=market-time.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market-time.d.ts","sourceRoot":"","sources":["../../src/market-time.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAEhB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AAInC,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAahB,CAAC;
|
|
1
|
+
{"version":3,"file":"market-time.d.ts","sourceRoot":"","sources":["../../src/market-time.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAEhB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AAInC,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAahB,CAAC;AA+iBX;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAO,GAAG,qBAAqB,CAGvF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,gBAAqB,GAAG;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,IAAI,CAAA;CAAE,CAM7F;AAED;;GAEG;AACH;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,GAAE,IAAiB,GAAG,IAAI,CAE3E;AAED;;GAEG;AACH;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,GAAE,IAAiB,GAAG;IAAE,IAAI,EAAE,IAA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AAI;4BACL,IAAI;8BACF,IAAI;EAEjC;AAGD;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,iBAAiB,CAAoB;gBACjC,QAAQ,GAAE,MAA+B,EAAE,iBAAiB,GAAE,iBAAkC;IAG5G,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAGhC,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAGxC,sBAAsB,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI;IAGzC,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAGlC,kBAAkB,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,IAAI,CAAA;KAAE,GAAG,qBAAqB;IAGpE,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,GAAG,WAAW;IAG1D,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAGpC,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI;CAG7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,GAAE,IAAiB,GAAG;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CA0DA;AAGD,eAAO,MAAM,YAAY,EAAE,iBA0B1B,CAAC"}
|
|
@@ -116,6 +116,7 @@ export declare const disco: {
|
|
|
116
116
|
getNYTimeZone: typeof mt.getNYTimeZone;
|
|
117
117
|
getTradingDate: typeof mt.getTradingDate;
|
|
118
118
|
getTradingStartAndEndDates: typeof mt.getTradingStartAndEndDates;
|
|
119
|
+
countTradingDays: typeof mt.countTradingDays;
|
|
119
120
|
MARKET_TIMES: Types.MarketTimesConfig;
|
|
120
121
|
};
|
|
121
122
|
utils: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAK3C,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;kBA4Bd,CAAF;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAK3C,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;kBA4Bd,CAAF;;;kBAqCwI,CAAC;;;kBAA4zC,CAAC;;;kBAAkwC,CAAC;;;kBAAisD,CAAC;gBAAkB,CAAC;iBAAmB,CAAC;iBAAmB,CAAC;gBAAkB,CAAC;;;;;;;;;;;;;;;;;;kBAlDv8I,CAAC;;;kBAkDipS,CAAC;oBAAsB,CAAC;sBAAyB,CAAC;;;kBAAhxP,CAAC;;;kBAAwjc,CAAC;qBAAuB,CAAC;uBAAkC,CAAC;wBAAmC,CAAC;uBAAkC,CAAC;wBAAmC,CAAC;iBAA4B,CAAC;iBAA2B,CAAC;gBAAkB,CAAC;;;;;eAA5/W,CAAC;;;iBAAiE,CAAC;;kBAAmC,CAAC;;;;;kBAA65Q,CAAC;oBAAsB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADnxZ,CAAC"}
|
|
@@ -34,9 +34,19 @@ export declare const MARKET_CONFIG: {
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Returns market open/close times for a given date.
|
|
39
|
+
* @param options - { date?: Date }
|
|
40
|
+
* @returns MarketOpenCloseResult
|
|
41
|
+
*/
|
|
37
42
|
export declare function getMarketOpenClose(options?: {
|
|
38
43
|
date?: Date;
|
|
39
44
|
}): MarketOpenCloseResult;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the start and end dates for a market time period as Date objects.
|
|
47
|
+
* @param params - MarketTimeParams
|
|
48
|
+
* @returns Object with start and end Date
|
|
49
|
+
*/
|
|
40
50
|
export declare function getStartAndEndDates(params?: MarketTimeParams): {
|
|
41
51
|
start: Date;
|
|
42
52
|
end: Date;
|
|
@@ -44,14 +54,29 @@ export declare function getStartAndEndDates(params?: MarketTimeParams): {
|
|
|
44
54
|
/**
|
|
45
55
|
* Returns the last full trading date as a Date object.
|
|
46
56
|
*/
|
|
57
|
+
/**
|
|
58
|
+
* Returns the last full trading date as a Date object.
|
|
59
|
+
* @param currentDate - Date object (default: now)
|
|
60
|
+
* @returns Date object for last full trading date
|
|
61
|
+
*/
|
|
47
62
|
export declare function getLastFullTradingDate(currentDate?: Date): Date;
|
|
48
63
|
/**
|
|
49
64
|
* Returns the last full trading date and formatted YYYYMMDD string.
|
|
50
65
|
*/
|
|
66
|
+
/**
|
|
67
|
+
* Returns the last full trading date and formatted YYYY-MM-DD string.
|
|
68
|
+
* @param currentDate - Date object (default: now)
|
|
69
|
+
* @returns Object with date and YYYYMMDD string
|
|
70
|
+
*/
|
|
51
71
|
export declare function getLastFullTradingDateInfo(currentDate?: Date): {
|
|
52
72
|
date: Date;
|
|
53
73
|
YYYYMMDD: string;
|
|
54
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Returns the next market day after the reference date.
|
|
77
|
+
* @param referenceDate - Date object (default: now)
|
|
78
|
+
* @returns Object with date, yyyymmdd string, and ISO string
|
|
79
|
+
*/
|
|
55
80
|
export declare function getNextMarketDay({ referenceDate }?: {
|
|
56
81
|
referenceDate?: Date;
|
|
57
82
|
}): {
|
|
@@ -64,18 +89,49 @@ export declare function getNextMarketDay({ referenceDate }?: {
|
|
|
64
89
|
* @param time - a string, number (unix timestamp), or Date object representing the time
|
|
65
90
|
* @returns the trading date as a string in YYYY-MM-DD format
|
|
66
91
|
*/
|
|
92
|
+
/**
|
|
93
|
+
* Returns the trading date for a given time in YYYY-MM-DD format (NY time).
|
|
94
|
+
* @param time - string, number, or Date
|
|
95
|
+
* @returns trading date string
|
|
96
|
+
*/
|
|
67
97
|
export declare function getTradingDate(time: string | number | Date): string;
|
|
98
|
+
/**
|
|
99
|
+
* Returns the NY timezone offset string for a given date.
|
|
100
|
+
* @param date - Date object (default: now)
|
|
101
|
+
* @returns '-04:00' for EDT, '-05:00' for EST
|
|
102
|
+
*/
|
|
68
103
|
export declare function getNYTimeZone(date?: Date): '-04:00' | '-05:00';
|
|
104
|
+
/**
|
|
105
|
+
* Returns the current market status for a given date.
|
|
106
|
+
* @param options - { date?: Date }
|
|
107
|
+
* @returns MarketStatus object
|
|
108
|
+
*/
|
|
69
109
|
export declare function getMarketStatus(options?: {
|
|
70
110
|
date?: Date;
|
|
71
111
|
}): MarketStatus;
|
|
112
|
+
/**
|
|
113
|
+
* Checks if a date is a market day.
|
|
114
|
+
* @param date - Date object
|
|
115
|
+
* @returns true if market day, false otherwise
|
|
116
|
+
*/
|
|
72
117
|
export declare function isMarketDay(date: Date): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Checks if a date/time is within market hours, extended hours, or continuous.
|
|
120
|
+
* @param date - Date object
|
|
121
|
+
* @param intradayReporting - 'market_hours', 'extended_hours', or 'continuous'
|
|
122
|
+
* @returns true if within hours, false otherwise
|
|
123
|
+
*/
|
|
73
124
|
export declare function isWithinMarketHours(date: Date, intradayReporting?: IntradayReporting): boolean;
|
|
74
125
|
/**
|
|
75
126
|
* Returns full trading days from market open to market close.
|
|
76
127
|
* endDate is always the most recent market close (previous day's close if before open, today's close if after open).
|
|
77
128
|
* days: 1 or not specified = that day's open; 2 = previous market day's open, etc.
|
|
78
129
|
*/
|
|
130
|
+
/**
|
|
131
|
+
* Returns full trading days from market open to market close.
|
|
132
|
+
* @param options - { endDate?: Date, days?: number }
|
|
133
|
+
* @returns Object with startDate and endDate
|
|
134
|
+
*/
|
|
79
135
|
export declare function getTradingStartAndEndDates(options?: {
|
|
80
136
|
endDate?: Date;
|
|
81
137
|
days?: number;
|
|
@@ -83,6 +139,12 @@ export declare function getTradingStartAndEndDates(options?: {
|
|
|
83
139
|
startDate: Date;
|
|
84
140
|
endDate: Date;
|
|
85
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* Creates a MarketTime utility instance with helper methods.
|
|
144
|
+
* @param timezone - Optional timezone string
|
|
145
|
+
* @param intradayReporting - Optional intraday reporting mode
|
|
146
|
+
* @returns Utility object with market time methods
|
|
147
|
+
*/
|
|
86
148
|
export declare function createMarketTimeUtil(timezone?: string, intradayReporting?: IntradayReporting): {
|
|
87
149
|
isMarketDay: (date: Date) => boolean;
|
|
88
150
|
isWithinMarketHours: (date: Date) => boolean;
|
|
@@ -96,6 +158,9 @@ export declare function createMarketTimeUtil(timezone?: string, intradayReportin
|
|
|
96
158
|
isEarlyCloseDay: (date: Date) => boolean;
|
|
97
159
|
getEarlyCloseTime: (date: Date) => number | null;
|
|
98
160
|
};
|
|
161
|
+
/**
|
|
162
|
+
* Backward compatibility class for MarketTime utilities.
|
|
163
|
+
*/
|
|
99
164
|
export declare class MarketTimeUtil {
|
|
100
165
|
private intradayReporting;
|
|
101
166
|
constructor(timezone?: string, intradayReporting?: IntradayReporting);
|
|
@@ -110,5 +175,37 @@ export declare class MarketTimeUtil {
|
|
|
110
175
|
isEarlyCloseDay(date: Date): boolean;
|
|
111
176
|
getEarlyCloseTime(date: Date): number | null;
|
|
112
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Counts trading time between two dates (passed as standard Date objects), excluding weekends and holidays, and closed market hours, using other functions in this library.
|
|
180
|
+
*
|
|
181
|
+
* This function calculates the actual trading time between two dates by:
|
|
182
|
+
* 1. Iterating through each calendar day between startDate and endDate (inclusive)
|
|
183
|
+
* 2. For each day that is a market day (not weekend/holiday), getting market open/close times
|
|
184
|
+
* 3. Calculating the overlap between the time range and market hours for that day
|
|
185
|
+
* 4. Summing up all the trading minutes across all days
|
|
186
|
+
*
|
|
187
|
+
* The function automatically handles:
|
|
188
|
+
* - Weekends (Saturday/Sunday) - skipped entirely
|
|
189
|
+
* - Market holidays - skipped entirely
|
|
190
|
+
* - Early close days (e.g. day before holidays) - uses early close time
|
|
191
|
+
* - Times outside market hours - only counts time within 9:30am-4pm ET (or early close)
|
|
192
|
+
*
|
|
193
|
+
* Examples:
|
|
194
|
+
* - 12pm to 3:30pm same day = 3.5 hours = 210 minutes = 0.54 days
|
|
195
|
+
* - 9:30am to 4pm same day = 6.5 hours = 390 minutes = 1 day
|
|
196
|
+
* - Friday 2pm to Monday 2pm = 6.5 hours (Friday 2pm-4pm + Monday 9:30am-2pm)
|
|
197
|
+
*
|
|
198
|
+
* @param startDate - Start date/time
|
|
199
|
+
* @param endDate - End date/time (default: now)
|
|
200
|
+
* @returns Object containing:
|
|
201
|
+
* - days: Trading time as fraction of full trading days (6.5 hours = 1 day)
|
|
202
|
+
* - hours: Trading time in hours
|
|
203
|
+
* - minutes: Trading time in minutes
|
|
204
|
+
*/
|
|
205
|
+
export declare function countTradingDays(startDate: Date, endDate?: Date): {
|
|
206
|
+
days: number;
|
|
207
|
+
hours: number;
|
|
208
|
+
minutes: number;
|
|
209
|
+
};
|
|
113
210
|
export declare const MARKET_TIMES: MarketTimesConfig;
|
|
114
211
|
//# sourceMappingURL=market-time.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market-time.d.ts","sourceRoot":"","sources":["../../src/market-time.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAEhB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AAInC,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAahB,CAAC;
|
|
1
|
+
{"version":3,"file":"market-time.d.ts","sourceRoot":"","sources":["../../src/market-time.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAEhB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AAInC,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAahB,CAAC;AA+iBX;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAO,GAAG,qBAAqB,CAGvF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,gBAAqB,GAAG;IA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ig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.20",
|
|
7
7
|
"author": "Disco Media",
|
|
8
8
|
"description": "Utility functions used in Disco Media apps",
|
|
9
9
|
"always-build-npm": true,
|
|
@@ -32,12 +32,10 @@
|
|
|
32
32
|
"test": "npm run build && node dist/test.js"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"dotenv": "^17.2.0",
|
|
38
|
-
"ms": "^2.1.3",
|
|
39
|
-
"openai": "^5.10.1",
|
|
35
|
+
"dotenv": "^17.2.1",
|
|
36
|
+
"openai": "^5.10.2",
|
|
40
37
|
"p-limit": "^6.2.0",
|
|
38
|
+
"tslib": "^2.8.1",
|
|
41
39
|
"ws": "^8.18.3"
|
|
42
40
|
},
|
|
43
41
|
"license": "ISC",
|
|
@@ -46,11 +44,9 @@
|
|
|
46
44
|
"@rollup/plugin-json": "^6.1.0",
|
|
47
45
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
48
46
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
49
|
-
"@types/date-fns": "^2.6.3",
|
|
50
|
-
"@types/ms": "^2.1.0",
|
|
51
47
|
"@types/ws": "^8.18.1",
|
|
52
48
|
"lightweight-charts": "^5.0.8",
|
|
53
|
-
"rollup": "^4.45.
|
|
49
|
+
"rollup": "^4.45.3",
|
|
54
50
|
"typescript": "^5.8.3"
|
|
55
51
|
}
|
|
56
52
|
}
|