@discomedia/utils 1.0.19 → 1.0.21

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.
@@ -112,10 +112,15 @@ export declare const disco: {
112
112
  getMarketOpenClose: typeof mt.getMarketOpenClose;
113
113
  getLastFullTradingDate: typeof mt.getLastFullTradingDate;
114
114
  getNextMarketDay: typeof mt.getNextMarketDay;
115
+ getPreviousMarketDay: typeof mt.getPreviousMarketDay;
116
+ getMarketTimePeriod: typeof mt.getMarketTimePeriod;
115
117
  getMarketStatus: typeof mt.getMarketStatus;
116
118
  getNYTimeZone: typeof mt.getNYTimeZone;
117
119
  getTradingDate: typeof mt.getTradingDate;
118
120
  getTradingStartAndEndDates: typeof mt.getTradingStartAndEndDates;
121
+ isMarketDay: typeof mt.isMarketDay;
122
+ isWithinMarketHours: typeof mt.isWithinMarketHours;
123
+ countTradingDays: typeof mt.countTradingDays;
119
124
  MARKET_TIMES: Types.MarketTimesConfig;
120
125
  };
121
126
  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,0B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BAsCA,CAAC;;;kBAIguC,CAAC;;;kBAAkwC,CAAC;;;kBAAisD,CAAC;gBAAkB,CAAC;iBAAmB,CAAC;iBAAmB,CAAC;gBAAkB,CAAC;;;;;;;;;;;;;;;;;;kBAvDrtI,CAAC;;;kBAuD+5R,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADljZ,CAAC"}
@@ -34,9 +34,32 @@ export declare const MARKET_CONFIG: {
34
34
  };
35
35
  };
36
36
  };
37
+ /**
38
+ * Checks if a date/time is within market hours, extended hours, or continuous.
39
+ * @param date - Date object
40
+ * @param intradayReporting - 'market_hours', 'extended_hours', or 'continuous'
41
+ * @returns true if within hours, false otherwise
42
+ */
43
+ export declare function isWithinMarketHours(date: Date, intradayReporting?: IntradayReporting): boolean;
44
+ /**
45
+ * Returns the start and end dates for a market time period.
46
+ * @param params - MarketTimeParams
47
+ * @returns PeriodDates object
48
+ */
49
+ export declare function getMarketTimePeriod(params: MarketTimeParams): PeriodDates;
50
+ /**
51
+ * Returns market open/close times for a given date.
52
+ * @param options - { date?: Date }
53
+ * @returns MarketOpenCloseResult
54
+ */
37
55
  export declare function getMarketOpenClose(options?: {
38
56
  date?: Date;
39
57
  }): MarketOpenCloseResult;
58
+ /**
59
+ * Returns the start and end dates for a market time period as Date objects.
60
+ * @param params - MarketTimeParams
61
+ * @returns Object with start and end Date
62
+ */
40
63
  export declare function getStartAndEndDates(params?: MarketTimeParams): {
41
64
  start: Date;
42
65
  end: Date;
@@ -44,14 +67,29 @@ export declare function getStartAndEndDates(params?: MarketTimeParams): {
44
67
  /**
45
68
  * Returns the last full trading date as a Date object.
46
69
  */
70
+ /**
71
+ * Returns the last full trading date as a Date object.
72
+ * @param currentDate - Date object (default: now)
73
+ * @returns Date object for last full trading date
74
+ */
47
75
  export declare function getLastFullTradingDate(currentDate?: Date): Date;
48
76
  /**
49
77
  * Returns the last full trading date and formatted YYYYMMDD string.
50
78
  */
79
+ /**
80
+ * Returns the last full trading date and formatted YYYY-MM-DD string.
81
+ * @param currentDate - Date object (default: now)
82
+ * @returns Object with date and YYYYMMDD string
83
+ */
51
84
  export declare function getLastFullTradingDateInfo(currentDate?: Date): {
52
85
  date: Date;
53
86
  YYYYMMDD: string;
54
87
  };
88
+ /**
89
+ * Returns the next market day after the reference date.
90
+ * @param referenceDate - Date object (default: now)
91
+ * @returns Object with date, yyyymmdd string, and ISO string
92
+ */
55
93
  export declare function getNextMarketDay({ referenceDate }?: {
56
94
  referenceDate?: Date;
57
95
  }): {
@@ -59,23 +97,59 @@ export declare function getNextMarketDay({ referenceDate }?: {
59
97
  yyyymmdd: string;
60
98
  dateISOString: string;
61
99
  };
100
+ /**
101
+ * Returns the previous market day before the reference date.
102
+ * @param referenceDate - Date object (default: now)
103
+ * @returns Object with date, yyyymmdd string, and ISO string
104
+ */
105
+ export declare function getPreviousMarketDay({ referenceDate }?: {
106
+ referenceDate?: Date;
107
+ }): {
108
+ date: Date;
109
+ yyyymmdd: string;
110
+ dateISOString: string;
111
+ };
62
112
  /**
63
113
  * Returns the trading date for a given time. Note: Just trims the date string; does not validate if the date is a market day.
64
114
  * @param time - a string, number (unix timestamp), or Date object representing the time
65
115
  * @returns the trading date as a string in YYYY-MM-DD format
66
116
  */
117
+ /**
118
+ * Returns the trading date for a given time in YYYY-MM-DD format (NY time).
119
+ * @param time - string, number, or Date
120
+ * @returns trading date string
121
+ */
67
122
  export declare function getTradingDate(time: string | number | Date): string;
123
+ /**
124
+ * Returns the NY timezone offset string for a given date.
125
+ * @param date - Date object (default: now)
126
+ * @returns '-04:00' for EDT, '-05:00' for EST
127
+ */
68
128
  export declare function getNYTimeZone(date?: Date): '-04:00' | '-05:00';
129
+ /**
130
+ * Returns the current market status for a given date.
131
+ * @param options - { date?: Date }
132
+ * @returns MarketStatus object
133
+ */
69
134
  export declare function getMarketStatus(options?: {
70
135
  date?: Date;
71
136
  }): MarketStatus;
137
+ /**
138
+ * Checks if a date is a market day.
139
+ * @param date - Date object
140
+ * @returns true if market day, false otherwise
141
+ */
72
142
  export declare function isMarketDay(date: Date): boolean;
73
- export declare function isWithinMarketHours(date: Date, intradayReporting?: IntradayReporting): boolean;
74
143
  /**
75
144
  * Returns full trading days from market open to market close.
76
145
  * endDate is always the most recent market close (previous day's close if before open, today's close if after open).
77
146
  * days: 1 or not specified = that day's open; 2 = previous market day's open, etc.
78
147
  */
148
+ /**
149
+ * Returns full trading days from market open to market close.
150
+ * @param options - { endDate?: Date, days?: number }
151
+ * @returns Object with startDate and endDate
152
+ */
79
153
  export declare function getTradingStartAndEndDates(options?: {
80
154
  endDate?: Date;
81
155
  days?: number;
@@ -83,32 +157,37 @@ export declare function getTradingStartAndEndDates(options?: {
83
157
  startDate: Date;
84
158
  endDate: Date;
85
159
  };
86
- export declare function createMarketTimeUtil(timezone?: string, intradayReporting?: IntradayReporting): {
87
- isMarketDay: (date: Date) => boolean;
88
- isWithinMarketHours: (date: Date) => boolean;
89
- getLastFullTradingDate: (date?: Date) => Date;
90
- getNextMarketDay: (date: Date) => Date;
91
- getMarketOpenClose: (options?: {
92
- date?: Date;
93
- }) => MarketOpenCloseResult;
94
- getMarketTimePeriod: (params: MarketTimeParams) => PeriodDates;
95
- getMarketStatus: (date?: Date) => MarketStatus;
96
- isEarlyCloseDay: (date: Date) => boolean;
97
- getEarlyCloseTime: (date: Date) => number | null;
160
+ /**
161
+ * 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.
162
+ *
163
+ * This function calculates the actual trading time between two dates by:
164
+ * 1. Iterating through each calendar day between startDate and endDate (inclusive)
165
+ * 2. For each day that is a market day (not weekend/holiday), getting market open/close times
166
+ * 3. Calculating the overlap between the time range and market hours for that day
167
+ * 4. Summing up all the trading minutes across all days
168
+ *
169
+ * The function automatically handles:
170
+ * - Weekends (Saturday/Sunday) - skipped entirely
171
+ * - Market holidays - skipped entirely
172
+ * - Early close days (e.g. day before holidays) - uses early close time
173
+ * - Times outside market hours - only counts time within 9:30am-4pm ET (or early close)
174
+ *
175
+ * Examples:
176
+ * - 12pm to 3:30pm same day = 3.5 hours = 210 minutes = 0.54 days
177
+ * - 9:30am to 4pm same day = 6.5 hours = 390 minutes = 1 day
178
+ * - Friday 2pm to Monday 2pm = 6.5 hours (Friday 2pm-4pm + Monday 9:30am-2pm)
179
+ *
180
+ * @param startDate - Start date/time
181
+ * @param endDate - End date/time (default: now)
182
+ * @returns Object containing:
183
+ * - days: Trading time as fraction of full trading days (6.5 hours = 1 day)
184
+ * - hours: Trading time in hours
185
+ * - minutes: Trading time in minutes
186
+ */
187
+ export declare function countTradingDays(startDate: Date, endDate?: Date): {
188
+ days: number;
189
+ hours: number;
190
+ minutes: number;
98
191
  };
99
- export declare class MarketTimeUtil {
100
- private intradayReporting;
101
- constructor(timezone?: string, intradayReporting?: IntradayReporting);
102
- isMarketDay(date: Date): boolean;
103
- isWithinMarketHours(date: Date): boolean;
104
- getLastFullTradingDate(date?: Date): Date;
105
- getNextMarketDay(date: Date): Date;
106
- getMarketOpenClose(options?: {
107
- date?: Date;
108
- }): MarketOpenCloseResult;
109
- getMarketTimePeriod(params: MarketTimeParams): PeriodDates;
110
- isEarlyCloseDay(date: Date): boolean;
111
- getEarlyCloseTime(date: Date): number | null;
112
- }
113
192
  export declare const MARKET_TIMES: MarketTimesConfig;
114
193
  //# 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,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,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAMnE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ,CAG9D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAO,GAAG,YAAY,CAG3E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAG/C;AAED;;;;GAIG;AACH;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACV,GACL;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,IAAI,CAAA;CAAE,CA0CpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,IAAI,EACf,OAAO,GAAE,IAAiB,GACzB;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAuDA;AAGD,eAAO,MAAM,YAAY,EAAE,iBA0B1B,CAAC"}
@@ -112,10 +112,15 @@ export declare const disco: {
112
112
  getMarketOpenClose: typeof mt.getMarketOpenClose;
113
113
  getLastFullTradingDate: typeof mt.getLastFullTradingDate;
114
114
  getNextMarketDay: typeof mt.getNextMarketDay;
115
+ getPreviousMarketDay: typeof mt.getPreviousMarketDay;
116
+ getMarketTimePeriod: typeof mt.getMarketTimePeriod;
115
117
  getMarketStatus: typeof mt.getMarketStatus;
116
118
  getNYTimeZone: typeof mt.getNYTimeZone;
117
119
  getTradingDate: typeof mt.getTradingDate;
118
120
  getTradingStartAndEndDates: typeof mt.getTradingStartAndEndDates;
121
+ isMarketDay: typeof mt.isMarketDay;
122
+ isWithinMarketHours: typeof mt.isWithinMarketHours;
123
+ countTradingDays: typeof mt.countTradingDays;
119
124
  MARKET_TIMES: Types.MarketTimesConfig;
120
125
  };
121
126
  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;;;kBAoCmL,CAAC;;;kBAA4zC,CAAC;;;kBAAkwC,CAAC;;;kBAAisD,CAAC;gBAAkB,CAAC;iBAAmB,CAAC;iBAAmB,CAAC;gBAAkB,CAAC;;;;;;;;;;;;;;;;;;kBAjDl/I,CAAC;;;kBAiD4rS,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,C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;;;;CADljZ,CAAC"}
@@ -34,9 +34,32 @@ export declare const MARKET_CONFIG: {
34
34
  };
35
35
  };
36
36
  };
37
+ /**
38
+ * Checks if a date/time is within market hours, extended hours, or continuous.
39
+ * @param date - Date object
40
+ * @param intradayReporting - 'market_hours', 'extended_hours', or 'continuous'
41
+ * @returns true if within hours, false otherwise
42
+ */
43
+ export declare function isWithinMarketHours(date: Date, intradayReporting?: IntradayReporting): boolean;
44
+ /**
45
+ * Returns the start and end dates for a market time period.
46
+ * @param params - MarketTimeParams
47
+ * @returns PeriodDates object
48
+ */
49
+ export declare function getMarketTimePeriod(params: MarketTimeParams): PeriodDates;
50
+ /**
51
+ * Returns market open/close times for a given date.
52
+ * @param options - { date?: Date }
53
+ * @returns MarketOpenCloseResult
54
+ */
37
55
  export declare function getMarketOpenClose(options?: {
38
56
  date?: Date;
39
57
  }): MarketOpenCloseResult;
58
+ /**
59
+ * Returns the start and end dates for a market time period as Date objects.
60
+ * @param params - MarketTimeParams
61
+ * @returns Object with start and end Date
62
+ */
40
63
  export declare function getStartAndEndDates(params?: MarketTimeParams): {
41
64
  start: Date;
42
65
  end: Date;
@@ -44,14 +67,29 @@ export declare function getStartAndEndDates(params?: MarketTimeParams): {
44
67
  /**
45
68
  * Returns the last full trading date as a Date object.
46
69
  */
70
+ /**
71
+ * Returns the last full trading date as a Date object.
72
+ * @param currentDate - Date object (default: now)
73
+ * @returns Date object for last full trading date
74
+ */
47
75
  export declare function getLastFullTradingDate(currentDate?: Date): Date;
48
76
  /**
49
77
  * Returns the last full trading date and formatted YYYYMMDD string.
50
78
  */
79
+ /**
80
+ * Returns the last full trading date and formatted YYYY-MM-DD string.
81
+ * @param currentDate - Date object (default: now)
82
+ * @returns Object with date and YYYYMMDD string
83
+ */
51
84
  export declare function getLastFullTradingDateInfo(currentDate?: Date): {
52
85
  date: Date;
53
86
  YYYYMMDD: string;
54
87
  };
88
+ /**
89
+ * Returns the next market day after the reference date.
90
+ * @param referenceDate - Date object (default: now)
91
+ * @returns Object with date, yyyymmdd string, and ISO string
92
+ */
55
93
  export declare function getNextMarketDay({ referenceDate }?: {
56
94
  referenceDate?: Date;
57
95
  }): {
@@ -59,23 +97,59 @@ export declare function getNextMarketDay({ referenceDate }?: {
59
97
  yyyymmdd: string;
60
98
  dateISOString: string;
61
99
  };
100
+ /**
101
+ * Returns the previous market day before the reference date.
102
+ * @param referenceDate - Date object (default: now)
103
+ * @returns Object with date, yyyymmdd string, and ISO string
104
+ */
105
+ export declare function getPreviousMarketDay({ referenceDate }?: {
106
+ referenceDate?: Date;
107
+ }): {
108
+ date: Date;
109
+ yyyymmdd: string;
110
+ dateISOString: string;
111
+ };
62
112
  /**
63
113
  * Returns the trading date for a given time. Note: Just trims the date string; does not validate if the date is a market day.
64
114
  * @param time - a string, number (unix timestamp), or Date object representing the time
65
115
  * @returns the trading date as a string in YYYY-MM-DD format
66
116
  */
117
+ /**
118
+ * Returns the trading date for a given time in YYYY-MM-DD format (NY time).
119
+ * @param time - string, number, or Date
120
+ * @returns trading date string
121
+ */
67
122
  export declare function getTradingDate(time: string | number | Date): string;
123
+ /**
124
+ * Returns the NY timezone offset string for a given date.
125
+ * @param date - Date object (default: now)
126
+ * @returns '-04:00' for EDT, '-05:00' for EST
127
+ */
68
128
  export declare function getNYTimeZone(date?: Date): '-04:00' | '-05:00';
129
+ /**
130
+ * Returns the current market status for a given date.
131
+ * @param options - { date?: Date }
132
+ * @returns MarketStatus object
133
+ */
69
134
  export declare function getMarketStatus(options?: {
70
135
  date?: Date;
71
136
  }): MarketStatus;
137
+ /**
138
+ * Checks if a date is a market day.
139
+ * @param date - Date object
140
+ * @returns true if market day, false otherwise
141
+ */
72
142
  export declare function isMarketDay(date: Date): boolean;
73
- export declare function isWithinMarketHours(date: Date, intradayReporting?: IntradayReporting): boolean;
74
143
  /**
75
144
  * Returns full trading days from market open to market close.
76
145
  * endDate is always the most recent market close (previous day's close if before open, today's close if after open).
77
146
  * days: 1 or not specified = that day's open; 2 = previous market day's open, etc.
78
147
  */
148
+ /**
149
+ * Returns full trading days from market open to market close.
150
+ * @param options - { endDate?: Date, days?: number }
151
+ * @returns Object with startDate and endDate
152
+ */
79
153
  export declare function getTradingStartAndEndDates(options?: {
80
154
  endDate?: Date;
81
155
  days?: number;
@@ -83,32 +157,37 @@ export declare function getTradingStartAndEndDates(options?: {
83
157
  startDate: Date;
84
158
  endDate: Date;
85
159
  };
86
- export declare function createMarketTimeUtil(timezone?: string, intradayReporting?: IntradayReporting): {
87
- isMarketDay: (date: Date) => boolean;
88
- isWithinMarketHours: (date: Date) => boolean;
89
- getLastFullTradingDate: (date?: Date) => Date;
90
- getNextMarketDay: (date: Date) => Date;
91
- getMarketOpenClose: (options?: {
92
- date?: Date;
93
- }) => MarketOpenCloseResult;
94
- getMarketTimePeriod: (params: MarketTimeParams) => PeriodDates;
95
- getMarketStatus: (date?: Date) => MarketStatus;
96
- isEarlyCloseDay: (date: Date) => boolean;
97
- getEarlyCloseTime: (date: Date) => number | null;
160
+ /**
161
+ * 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.
162
+ *
163
+ * This function calculates the actual trading time between two dates by:
164
+ * 1. Iterating through each calendar day between startDate and endDate (inclusive)
165
+ * 2. For each day that is a market day (not weekend/holiday), getting market open/close times
166
+ * 3. Calculating the overlap between the time range and market hours for that day
167
+ * 4. Summing up all the trading minutes across all days
168
+ *
169
+ * The function automatically handles:
170
+ * - Weekends (Saturday/Sunday) - skipped entirely
171
+ * - Market holidays - skipped entirely
172
+ * - Early close days (e.g. day before holidays) - uses early close time
173
+ * - Times outside market hours - only counts time within 9:30am-4pm ET (or early close)
174
+ *
175
+ * Examples:
176
+ * - 12pm to 3:30pm same day = 3.5 hours = 210 minutes = 0.54 days
177
+ * - 9:30am to 4pm same day = 6.5 hours = 390 minutes = 1 day
178
+ * - Friday 2pm to Monday 2pm = 6.5 hours (Friday 2pm-4pm + Monday 9:30am-2pm)
179
+ *
180
+ * @param startDate - Start date/time
181
+ * @param endDate - End date/time (default: now)
182
+ * @returns Object containing:
183
+ * - days: Trading time as fraction of full trading days (6.5 hours = 1 day)
184
+ * - hours: Trading time in hours
185
+ * - minutes: Trading time in minutes
186
+ */
187
+ export declare function countTradingDays(startDate: Date, endDate?: Date): {
188
+ days: number;
189
+ hours: number;
190
+ minutes: number;
98
191
  };
99
- export declare class MarketTimeUtil {
100
- private intradayReporting;
101
- constructor(timezone?: string, intradayReporting?: IntradayReporting);
102
- isMarketDay(date: Date): boolean;
103
- isWithinMarketHours(date: Date): boolean;
104
- getLastFullTradingDate(date?: Date): Date;
105
- getNextMarketDay(date: Date): Date;
106
- getMarketOpenClose(options?: {
107
- date?: Date;
108
- }): MarketOpenCloseResult;
109
- getMarketTimePeriod(params: MarketTimeParams): PeriodDates;
110
- isEarlyCloseDay(date: Date): boolean;
111
- getEarlyCloseTime(date: Date): number | null;
112
- }
113
192
  export declare const MARKET_TIMES: MarketTimesConfig;
114
193
  //# 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;AAicX,wBAAgB,kBAAkB,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAO,GAAG,qBAAqB,CAGvF;AAED,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,gBAAqB,GAAG;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,IAAI,CAAA;CAAE,CAM7F;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,GAAE,IAAiB,GAAG,IAAI,CAE3E;AAED;;GA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I,CAAC,EAAE,MAAM,CAAC;CACV,GACL;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,IAAI,CAAA;CAAE,CA0CpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,IAAI,EACf,OAAO,GAAE,IAAiB,GACzB;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAuDA;AAGD,eAAO,MAAM,YAAY,EAAE,iBA0B1B,CAAC"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.19",
6
+ "version": "1.0.21",
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
- "date-fns": "^4.1.0",
36
- "date-fns-tz": "^3.2.0",
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.1",
49
+ "rollup": "^4.45.3",
54
50
  "typescript": "^5.8.3"
55
51
  }
56
52
  }