ts-time-utils 1.0.0 → 2.0.0

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.
Files changed (102) hide show
  1. package/README.md +682 -11
  2. package/dist/calculate.d.ts +7 -2
  3. package/dist/calculate.d.ts.map +1 -1
  4. package/dist/calculate.js +37 -13
  5. package/dist/calendar.d.ts +103 -0
  6. package/dist/calendar.d.ts.map +1 -1
  7. package/dist/calendar.js +224 -0
  8. package/dist/compare.d.ts +217 -0
  9. package/dist/compare.d.ts.map +1 -0
  10. package/dist/compare.js +417 -0
  11. package/dist/countdown.d.ts +217 -0
  12. package/dist/countdown.d.ts.map +1 -0
  13. package/dist/countdown.js +298 -0
  14. package/dist/cron.d.ts +82 -0
  15. package/dist/cron.d.ts.map +1 -0
  16. package/dist/cron.js +294 -0
  17. package/dist/dateRange.d.ts +266 -0
  18. package/dist/dateRange.d.ts.map +1 -0
  19. package/dist/dateRange.js +433 -0
  20. package/dist/esm/calculate.d.ts +7 -2
  21. package/dist/esm/calculate.d.ts.map +1 -1
  22. package/dist/esm/calculate.js +37 -13
  23. package/dist/esm/calendar.d.ts +103 -0
  24. package/dist/esm/calendar.d.ts.map +1 -1
  25. package/dist/esm/calendar.js +224 -0
  26. package/dist/esm/compare.d.ts +217 -0
  27. package/dist/esm/compare.d.ts.map +1 -0
  28. package/dist/esm/compare.js +417 -0
  29. package/dist/esm/countdown.d.ts +217 -0
  30. package/dist/esm/countdown.d.ts.map +1 -0
  31. package/dist/esm/countdown.js +298 -0
  32. package/dist/esm/cron.d.ts +82 -0
  33. package/dist/esm/cron.d.ts.map +1 -0
  34. package/dist/esm/cron.js +294 -0
  35. package/dist/esm/dateRange.d.ts +266 -0
  36. package/dist/esm/dateRange.d.ts.map +1 -0
  37. package/dist/esm/dateRange.js +433 -0
  38. package/dist/esm/fiscal.d.ts +195 -0
  39. package/dist/esm/fiscal.d.ts.map +1 -0
  40. package/dist/esm/fiscal.js +295 -0
  41. package/dist/esm/format.d.ts +65 -0
  42. package/dist/esm/format.d.ts.map +1 -1
  43. package/dist/esm/format.js +202 -0
  44. package/dist/esm/index.d.ts +18 -7
  45. package/dist/esm/index.d.ts.map +1 -1
  46. package/dist/esm/index.js +22 -6
  47. package/dist/esm/iterate.d.ts +212 -0
  48. package/dist/esm/iterate.d.ts.map +1 -0
  49. package/dist/esm/iterate.js +409 -0
  50. package/dist/esm/naturalLanguage.d.ts +107 -0
  51. package/dist/esm/naturalLanguage.d.ts.map +1 -0
  52. package/dist/esm/naturalLanguage.js +344 -0
  53. package/dist/esm/parse.d.ts +45 -0
  54. package/dist/esm/parse.d.ts.map +1 -1
  55. package/dist/esm/parse.js +207 -0
  56. package/dist/esm/recurrence.d.ts +149 -0
  57. package/dist/esm/recurrence.d.ts.map +1 -0
  58. package/dist/esm/recurrence.js +404 -0
  59. package/dist/esm/timezone.d.ts +52 -0
  60. package/dist/esm/timezone.d.ts.map +1 -1
  61. package/dist/esm/timezone.js +171 -0
  62. package/dist/esm/types.d.ts +21 -0
  63. package/dist/esm/types.d.ts.map +1 -1
  64. package/dist/esm/validate.d.ts +51 -0
  65. package/dist/esm/validate.d.ts.map +1 -1
  66. package/dist/esm/validate.js +92 -0
  67. package/dist/esm/workingHours.d.ts +70 -0
  68. package/dist/esm/workingHours.d.ts.map +1 -1
  69. package/dist/esm/workingHours.js +161 -0
  70. package/dist/fiscal.d.ts +195 -0
  71. package/dist/fiscal.d.ts.map +1 -0
  72. package/dist/fiscal.js +295 -0
  73. package/dist/format.d.ts +65 -0
  74. package/dist/format.d.ts.map +1 -1
  75. package/dist/format.js +202 -0
  76. package/dist/index.d.ts +18 -7
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +22 -6
  79. package/dist/iterate.d.ts +212 -0
  80. package/dist/iterate.d.ts.map +1 -0
  81. package/dist/iterate.js +409 -0
  82. package/dist/naturalLanguage.d.ts +107 -0
  83. package/dist/naturalLanguage.d.ts.map +1 -0
  84. package/dist/naturalLanguage.js +344 -0
  85. package/dist/parse.d.ts +45 -0
  86. package/dist/parse.d.ts.map +1 -1
  87. package/dist/parse.js +207 -0
  88. package/dist/recurrence.d.ts +149 -0
  89. package/dist/recurrence.d.ts.map +1 -0
  90. package/dist/recurrence.js +404 -0
  91. package/dist/timezone.d.ts +52 -0
  92. package/dist/timezone.d.ts.map +1 -1
  93. package/dist/timezone.js +171 -0
  94. package/dist/types.d.ts +21 -0
  95. package/dist/types.d.ts.map +1 -1
  96. package/dist/validate.d.ts +51 -0
  97. package/dist/validate.d.ts.map +1 -1
  98. package/dist/validate.js +92 -0
  99. package/dist/workingHours.d.ts +70 -0
  100. package/dist/workingHours.d.ts.map +1 -1
  101. package/dist/workingHours.js +161 -0
  102. package/package.json +59 -12
@@ -97,3 +97,174 @@ export function reinterpretAsZone(date, targetZone) {
97
97
  return null;
98
98
  return new Date(Date.UTC(target.year, target.month - 1, target.day, target.hour, target.minute, target.second));
99
99
  }
100
+ /**
101
+ * Check if a date is in Daylight Saving Time for a given timezone
102
+ * @param date - date to check
103
+ * @param zone - IANA timezone string
104
+ */
105
+ export function isDST(date, zone) {
106
+ if (!isValidTimeZone(zone))
107
+ return null;
108
+ // Compare offset in January vs July - the one with larger offset is DST
109
+ const january = new Date(date.getFullYear(), 0, 1);
110
+ const july = new Date(date.getFullYear(), 6, 1);
111
+ const janOffset = getTimezoneOffset(zone, january);
112
+ const julOffset = getTimezoneOffset(zone, july);
113
+ const currentOffset = getTimezoneOffset(zone, date);
114
+ if (janOffset === null || julOffset === null || currentOffset === null) {
115
+ return null;
116
+ }
117
+ // If offsets are the same, no DST in this zone
118
+ if (janOffset === julOffset) {
119
+ return false;
120
+ }
121
+ // In northern hemisphere, summer (July) has larger offset
122
+ // In southern hemisphere, summer (January) has larger offset
123
+ // DST is whichever is the "larger" offset
124
+ const maxOffset = Math.max(janOffset, julOffset);
125
+ return currentOffset === maxOffset;
126
+ }
127
+ /**
128
+ * Get the next DST transition (if any) for a timezone
129
+ * @param date - starting date
130
+ * @param zone - IANA timezone string
131
+ * @returns next DST transition date or null if no DST in that zone
132
+ */
133
+ export function getNextDSTTransition(date, zone) {
134
+ if (!isValidTimeZone(zone))
135
+ return null;
136
+ const january = new Date(date.getFullYear(), 0, 1);
137
+ const july = new Date(date.getFullYear(), 6, 1);
138
+ const janOffset = getTimezoneOffset(zone, january);
139
+ const julOffset = getTimezoneOffset(zone, july);
140
+ if (janOffset === null || julOffset === null)
141
+ return null;
142
+ // No DST if offsets are the same
143
+ if (janOffset === julOffset)
144
+ return null;
145
+ // Binary search for the transition within the next year
146
+ const currentOffset = getTimezoneOffset(zone, date);
147
+ if (currentOffset === null)
148
+ return null;
149
+ // Check day by day for up to 366 days
150
+ const searchDate = new Date(date);
151
+ for (let i = 1; i <= 366; i++) {
152
+ searchDate.setDate(searchDate.getDate() + 1);
153
+ const newOffset = getTimezoneOffset(zone, searchDate);
154
+ if (newOffset !== null && newOffset !== currentOffset) {
155
+ // Found a transition, now narrow it down
156
+ const prevDay = new Date(searchDate);
157
+ prevDay.setDate(prevDay.getDate() - 1);
158
+ // Binary search within the day
159
+ let low = prevDay.getTime();
160
+ let high = searchDate.getTime();
161
+ while (high - low > 60000) { // 1 minute precision
162
+ const mid = Math.floor((low + high) / 2);
163
+ const midDate = new Date(mid);
164
+ const midOffset = getTimezoneOffset(zone, midDate);
165
+ if (midOffset === currentOffset) {
166
+ low = mid;
167
+ }
168
+ else {
169
+ high = mid;
170
+ }
171
+ }
172
+ return new Date(high);
173
+ }
174
+ }
175
+ return null;
176
+ }
177
+ /**
178
+ * Find overlapping working hours between multiple timezones
179
+ * @param zones - array of IANA timezone strings
180
+ * @param workHoursStart - work hours start (0-24)
181
+ * @param workHoursEnd - work hours end (0-24)
182
+ * @param date - reference date (default: today)
183
+ * @returns array of overlapping hour ranges in UTC, or null if no overlap
184
+ */
185
+ export function findCommonWorkingHours(zones, workHoursStart = 9, workHoursEnd = 17, date = new Date()) {
186
+ if (zones.length === 0)
187
+ return null;
188
+ // Convert each zone's work hours to UTC
189
+ const utcRanges = zones.map(zone => {
190
+ const offset = getTimezoneOffset(zone, date);
191
+ if (offset === null)
192
+ return null;
193
+ // Offset is in minutes, positive means ahead of UTC
194
+ // So to convert local time to UTC, we subtract the offset
195
+ const startUTC = workHoursStart - (offset / 60);
196
+ const endUTC = workHoursEnd - (offset / 60);
197
+ return { startUTC, endUTC };
198
+ });
199
+ if (utcRanges.some(r => r === null))
200
+ return null;
201
+ const validRanges = utcRanges;
202
+ // Find intersection of all ranges
203
+ let overlapStart = Math.max(...validRanges.map(r => r.startUTC));
204
+ let overlapEnd = Math.min(...validRanges.map(r => r.endUTC));
205
+ if (overlapStart >= overlapEnd) {
206
+ return null; // No overlap
207
+ }
208
+ return { startUTC: overlapStart, endUTC: overlapEnd };
209
+ }
210
+ /**
211
+ * Get all timezone abbreviations for a zone on a given date
212
+ * @param zone - IANA timezone string
213
+ * @param date - reference date
214
+ */
215
+ export function getTimezoneAbbreviation(zone, date = new Date()) {
216
+ try {
217
+ const fmt = new Intl.DateTimeFormat('en-US', {
218
+ timeZone: zone,
219
+ timeZoneName: 'short'
220
+ });
221
+ const parts = fmt.formatToParts(date);
222
+ const tzPart = parts.find(p => p.type === 'timeZoneName');
223
+ return tzPart?.value || null;
224
+ }
225
+ catch {
226
+ return null;
227
+ }
228
+ }
229
+ /**
230
+ * Convert a wall clock time from one timezone to another
231
+ * @param date - date with time in source timezone
232
+ * @param fromZone - source timezone
233
+ * @param toZone - target timezone
234
+ */
235
+ export function convertBetweenZones(date, fromZone, toZone) {
236
+ // First, interpret the date as being in fromZone
237
+ const fromOffset = getTimezoneOffset(fromZone, date);
238
+ const toOffset = getTimezoneOffset(toZone, date);
239
+ if (fromOffset === null || toOffset === null)
240
+ return null;
241
+ // Calculate the difference in minutes
242
+ const diffMinutes = toOffset - fromOffset;
243
+ // Apply the difference
244
+ const result = new Date(date.getTime() + diffMinutes * 60 * 1000);
245
+ return result;
246
+ }
247
+ /**
248
+ * Get the time difference between two timezones in hours
249
+ * @param zoneA - first timezone
250
+ * @param zoneB - second timezone
251
+ * @param date - reference date
252
+ */
253
+ export function getTimezoneDifferenceHours(zoneA, zoneB, date = new Date()) {
254
+ const diff = compareZoneOffsets(zoneA, zoneB, date);
255
+ if (diff === null)
256
+ return null;
257
+ return diff / 60;
258
+ }
259
+ /**
260
+ * Check if two timezones have the same offset at a given date
261
+ * @param zoneA - first timezone
262
+ * @param zoneB - second timezone
263
+ * @param date - reference date
264
+ */
265
+ export function isSameTimezone(zoneA, zoneB, date = new Date()) {
266
+ const diff = compareZoneOffsets(zoneA, zoneB, date);
267
+ if (diff === null)
268
+ return null;
269
+ return diff === 0;
270
+ }
@@ -104,6 +104,27 @@ export interface RecurrencePattern {
104
104
  count?: number;
105
105
  until?: Date;
106
106
  }
107
+ /** Recurrence frequency types */
108
+ export type RecurrenceFrequency = 'daily' | 'weekly' | 'monthly' | 'yearly';
109
+ /** Recurrence rule for repeating events (RRULE-inspired) */
110
+ export interface RecurrenceRule {
111
+ /** Frequency of recurrence */
112
+ frequency: RecurrenceFrequency;
113
+ /** Start date for the recurrence */
114
+ startDate: DateInput;
115
+ /** Interval between occurrences (default: 1) */
116
+ interval?: number;
117
+ /** Days of week (0=Sunday, 6=Saturday) */
118
+ byWeekday?: number[];
119
+ /** Days of month (1-31) */
120
+ byMonthDay?: number[];
121
+ /** Months of year (1-12) */
122
+ byMonth?: number[];
123
+ /** Number of occurrences (alternative to until) */
124
+ count?: number;
125
+ /** End date for recurrence (alternative to count) */
126
+ until?: DateInput;
127
+ }
107
128
  /** Locale-specific formatting options */
108
129
  export interface LocaleFormatOptions extends FormatOptions {
109
130
  /** Calendar system to use */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,4CAA4C;AAC5C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE/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C,mCAAmC;IACnC,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,uDAAuD;IACvD,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,yDAAyD;IACzD,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,uCAAuC;IACvC,OAAO,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC5B,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;CACrC"}
@@ -59,4 +59,55 @@ export declare function isValidTimeString(time: string): boolean;
59
59
  * @param dateString - date string to validate
60
60
  */
61
61
  export declare function isValidISOString(dateString: string): boolean;
62
+ /**
63
+ * Check if two dates are in the same week (ISO week, Monday-Sunday)
64
+ * @param date1 - first date
65
+ * @param date2 - second date
66
+ */
67
+ export declare function isSameWeek(date1: Date, date2: Date): boolean;
68
+ /**
69
+ * Check if two dates are in the same month
70
+ * @param date1 - first date
71
+ * @param date2 - second date
72
+ */
73
+ export declare function isSameMonth(date1: Date, date2: Date): boolean;
74
+ /**
75
+ * Check if two dates are in the same year
76
+ * @param date1 - first date
77
+ * @param date2 - second date
78
+ */
79
+ export declare function isSameYear(date1: Date, date2: Date): boolean;
80
+ /**
81
+ * Check if a date is in the current week
82
+ * @param date - date to check
83
+ */
84
+ export declare function isThisWeek(date: Date): boolean;
85
+ /**
86
+ * Check if a date is in the current month
87
+ * @param date - date to check
88
+ */
89
+ export declare function isThisMonth(date: Date): boolean;
90
+ /**
91
+ * Check if a date is in the current year
92
+ * @param date - date to check
93
+ */
94
+ export declare function isThisYear(date: Date): boolean;
95
+ /**
96
+ * Check if a date is a business day (weekday, optionally excluding holidays)
97
+ * @param date - date to check
98
+ * @param holidays - optional array of holiday dates to exclude
99
+ */
100
+ export declare function isBusinessDay(date: Date, holidays?: Date[]): boolean;
101
+ /**
102
+ * Check if a date is in the last N days (including today)
103
+ * @param date - date to check
104
+ * @param n - number of days
105
+ */
106
+ export declare function isInLastNDays(date: Date, n: number): boolean;
107
+ /**
108
+ * Check if a date is in the next N days (including today)
109
+ * @param date - date to check
110
+ * @param n - number of days
111
+ */
112
+ export declare function isInNextNDays(date: Date, n: number): boolean;
62
113
  //# sourceMappingURL=validate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAWjE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE1C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE5C;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAO3C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAQ/C;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAQ9C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAM3D;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAG7C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE7C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGvD;AAED;;;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BAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAK7D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAE5D;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE9C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE/C;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE9C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,GAAE,IAAI,EAAO,GAAG,OAAO,CAIxE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAU5D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAU5D"}
@@ -106,3 +106,95 @@ export function isValidISOString(dateString) {
106
106
  const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
107
107
  return isoRegex.test(dateString) && isValidDate(dateString);
108
108
  }
109
+ /**
110
+ * Check if two dates are in the same week (ISO week, Monday-Sunday)
111
+ * @param date1 - first date
112
+ * @param date2 - second date
113
+ */
114
+ export function isSameWeek(date1, date2) {
115
+ const getWeekStart = (d) => {
116
+ const date = new Date(d);
117
+ const day = date.getDay();
118
+ const diff = date.getDate() - day + (day === 0 ? -6 : 1); // Adjust for Monday start
119
+ date.setDate(diff);
120
+ date.setHours(0, 0, 0, 0);
121
+ return date;
122
+ };
123
+ return getWeekStart(date1).getTime() === getWeekStart(date2).getTime();
124
+ }
125
+ /**
126
+ * Check if two dates are in the same month
127
+ * @param date1 - first date
128
+ * @param date2 - second date
129
+ */
130
+ export function isSameMonth(date1, date2) {
131
+ return (date1.getMonth() === date2.getMonth() &&
132
+ date1.getFullYear() === date2.getFullYear());
133
+ }
134
+ /**
135
+ * Check if two dates are in the same year
136
+ * @param date1 - first date
137
+ * @param date2 - second date
138
+ */
139
+ export function isSameYear(date1, date2) {
140
+ return date1.getFullYear() === date2.getFullYear();
141
+ }
142
+ /**
143
+ * Check if a date is in the current week
144
+ * @param date - date to check
145
+ */
146
+ export function isThisWeek(date) {
147
+ return isSameWeek(date, new Date());
148
+ }
149
+ /**
150
+ * Check if a date is in the current month
151
+ * @param date - date to check
152
+ */
153
+ export function isThisMonth(date) {
154
+ return isSameMonth(date, new Date());
155
+ }
156
+ /**
157
+ * Check if a date is in the current year
158
+ * @param date - date to check
159
+ */
160
+ export function isThisYear(date) {
161
+ return isSameYear(date, new Date());
162
+ }
163
+ /**
164
+ * Check if a date is a business day (weekday, optionally excluding holidays)
165
+ * @param date - date to check
166
+ * @param holidays - optional array of holiday dates to exclude
167
+ */
168
+ export function isBusinessDay(date, holidays = []) {
169
+ if (isWeekend(date))
170
+ return false;
171
+ return !holidays.some(holiday => isSameDay(date, holiday));
172
+ }
173
+ /**
174
+ * Check if a date is in the last N days (including today)
175
+ * @param date - date to check
176
+ * @param n - number of days
177
+ */
178
+ export function isInLastNDays(date, n) {
179
+ const now = new Date();
180
+ const nDaysAgo = new Date(now);
181
+ nDaysAgo.setDate(nDaysAgo.getDate() - n);
182
+ nDaysAgo.setHours(0, 0, 0, 0);
183
+ const endOfToday = new Date(now);
184
+ endOfToday.setHours(23, 59, 59, 999);
185
+ return date >= nDaysAgo && date <= endOfToday;
186
+ }
187
+ /**
188
+ * Check if a date is in the next N days (including today)
189
+ * @param date - date to check
190
+ * @param n - number of days
191
+ */
192
+ export function isInNextNDays(date, n) {
193
+ const now = new Date();
194
+ const startOfToday = new Date(now);
195
+ startOfToday.setHours(0, 0, 0, 0);
196
+ const nDaysFromNow = new Date(now);
197
+ nDaysFromNow.setDate(nDaysFromNow.getDate() + n);
198
+ nDaysFromNow.setHours(23, 59, 59, 999);
199
+ return date >= startOfToday && date <= nDaysFromNow;
200
+ }
@@ -13,4 +13,74 @@ export declare function nextWorkingTime(date: Date, config?: WorkingHoursConfig)
13
13
  export declare function workingTimeBetween(start: Date, end: Date, config?: WorkingHoursConfig): number;
14
14
  /** Advance by working hours amount (simple iterative approach) */
15
15
  export declare function addWorkingHours(start: Date, hours: number, config?: WorkingHoursConfig): Date;
16
+ /**
17
+ * Add working days to a date
18
+ * @param start - start date
19
+ * @param days - number of working days to add
20
+ * @param config - working hours configuration
21
+ */
22
+ export declare function addWorkingDays(start: Date, days: number, config?: WorkingHoursConfig): Date;
23
+ /**
24
+ * Subtract working days from a date
25
+ * @param start - start date
26
+ * @param days - number of working days to subtract
27
+ * @param config - working hours configuration
28
+ */
29
+ export declare function subtractWorkingDays(start: Date, days: number, config?: WorkingHoursConfig): Date;
30
+ /**
31
+ * Get the next working day from a given date
32
+ * @param date - start date
33
+ * @param config - working hours configuration
34
+ */
35
+ export declare function getNextWorkingDay(date: Date, config?: WorkingHoursConfig): Date;
36
+ /**
37
+ * Get the previous working day from a given date
38
+ * @param date - start date
39
+ * @param config - working hours configuration
40
+ */
41
+ export declare function getPreviousWorkingDay(date: Date, config?: WorkingHoursConfig): Date;
42
+ /**
43
+ * Get the number of working days in a month
44
+ * @param year - year
45
+ * @param month - month (0-11)
46
+ * @param config - working hours configuration
47
+ */
48
+ export declare function getWorkingDaysInMonth(year: number, month: number, config?: WorkingHoursConfig): number;
49
+ /**
50
+ * Get all working days in a month as an array of dates
51
+ * @param year - year
52
+ * @param month - month (0-11)
53
+ * @param config - working hours configuration
54
+ */
55
+ export declare function getWorkingDaysInMonthArray(year: number, month: number, config?: WorkingHoursConfig): Date[];
56
+ /**
57
+ * Get working days between two dates (inclusive)
58
+ * @param start - start date
59
+ * @param end - end date
60
+ * @param config - working hours configuration
61
+ */
62
+ export declare function workingDaysBetween(start: Date, end: Date, config?: WorkingHoursConfig): number;
63
+ /**
64
+ * Check if a date is during work break
65
+ * @param date - date to check
66
+ * @param config - working hours configuration
67
+ */
68
+ export declare function isBreakTime(date: Date, config?: WorkingHoursConfig): boolean;
69
+ /**
70
+ * Get the start of the work day for a given date
71
+ * @param date - date to get work start for
72
+ * @param config - working hours configuration
73
+ */
74
+ export declare function getWorkDayStart(date: Date, config?: WorkingHoursConfig): Date;
75
+ /**
76
+ * Get the end of the work day for a given date
77
+ * @param date - date to get work end for
78
+ * @param config - working hours configuration
79
+ */
80
+ export declare function getWorkDayEnd(date: Date, config?: WorkingHoursConfig): Date;
81
+ /**
82
+ * Get the total working hours per day (excluding breaks)
83
+ * @param config - working hours configuration
84
+ */
85
+ export declare function getWorkingHoursPerDay(config?: WorkingHoursConfig): number;
16
86
  //# sourceMappingURL=workingHours.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workingHours.d.ts","sourceRoot":"","sources":["../../src/workingHours.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,eAAO,MAAM,qBAAqB,EAAE,kBAInC,CAAC;AAEF,kDAAkD;AAClD,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,OAAO,CAEpG;AAOD,uDAAuD;AACvD,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,OAAO,CAUrG;AAED,+CAA+C;AAC/C,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,IAAI,CAMpG;AAYD,kDAAkD;AAClD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,MAAM,CA+BrH;AAED,kEAAkE;AA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I,CAStG;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,IAAI,CAS1G;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,kBAA0C,GAAG,MAAM,CAY7H;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,kBAA0C,GAAG,IAAI,EAAE,CAYlI;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,MAAM,CAkBrH;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,OAAO,CASnG;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,IAAI,CAIpG;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,IAAI,CAIlG;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,GAAE,kBAA0C,GAAG,MAAM,CAUhG"}
@@ -107,3 +107,164 @@ export function addWorkingHours(start, hours, config = DEFAULT_WORKING_HOURS) {
107
107
  }
108
108
  return cursor;
109
109
  }
110
+ /**
111
+ * Add working days to a date
112
+ * @param start - start date
113
+ * @param days - number of working days to add
114
+ * @param config - working hours configuration
115
+ */
116
+ export function addWorkingDays(start, days, config = DEFAULT_WORKING_HOURS) {
117
+ if (days === 0)
118
+ return new Date(start);
119
+ const result = new Date(start);
120
+ const direction = days > 0 ? 1 : -1;
121
+ let remaining = Math.abs(days);
122
+ while (remaining > 0) {
123
+ result.setDate(result.getDate() + direction);
124
+ if (isWorkingDay(result, config)) {
125
+ remaining--;
126
+ }
127
+ }
128
+ return result;
129
+ }
130
+ /**
131
+ * Subtract working days from a date
132
+ * @param start - start date
133
+ * @param days - number of working days to subtract
134
+ * @param config - working hours configuration
135
+ */
136
+ export function subtractWorkingDays(start, days, config = DEFAULT_WORKING_HOURS) {
137
+ return addWorkingDays(start, -days, config);
138
+ }
139
+ /**
140
+ * Get the next working day from a given date
141
+ * @param date - start date
142
+ * @param config - working hours configuration
143
+ */
144
+ export function getNextWorkingDay(date, config = DEFAULT_WORKING_HOURS) {
145
+ const result = new Date(date);
146
+ result.setDate(result.getDate() + 1);
147
+ while (!isWorkingDay(result, config)) {
148
+ result.setDate(result.getDate() + 1);
149
+ }
150
+ return result;
151
+ }
152
+ /**
153
+ * Get the previous working day from a given date
154
+ * @param date - start date
155
+ * @param config - working hours configuration
156
+ */
157
+ export function getPreviousWorkingDay(date, config = DEFAULT_WORKING_HOURS) {
158
+ const result = new Date(date);
159
+ result.setDate(result.getDate() - 1);
160
+ while (!isWorkingDay(result, config)) {
161
+ result.setDate(result.getDate() - 1);
162
+ }
163
+ return result;
164
+ }
165
+ /**
166
+ * Get the number of working days in a month
167
+ * @param year - year
168
+ * @param month - month (0-11)
169
+ * @param config - working hours configuration
170
+ */
171
+ export function getWorkingDaysInMonth(year, month, config = DEFAULT_WORKING_HOURS) {
172
+ const daysInMonth = new Date(year, month + 1, 0).getDate();
173
+ let count = 0;
174
+ for (let day = 1; day <= daysInMonth; day++) {
175
+ const date = new Date(year, month, day);
176
+ if (isWorkingDay(date, config)) {
177
+ count++;
178
+ }
179
+ }
180
+ return count;
181
+ }
182
+ /**
183
+ * Get all working days in a month as an array of dates
184
+ * @param year - year
185
+ * @param month - month (0-11)
186
+ * @param config - working hours configuration
187
+ */
188
+ export function getWorkingDaysInMonthArray(year, month, config = DEFAULT_WORKING_HOURS) {
189
+ const daysInMonth = new Date(year, month + 1, 0).getDate();
190
+ const workingDays = [];
191
+ for (let day = 1; day <= daysInMonth; day++) {
192
+ const date = new Date(year, month, day);
193
+ if (isWorkingDay(date, config)) {
194
+ workingDays.push(date);
195
+ }
196
+ }
197
+ return workingDays;
198
+ }
199
+ /**
200
+ * Get working days between two dates (inclusive)
201
+ * @param start - start date
202
+ * @param end - end date
203
+ * @param config - working hours configuration
204
+ */
205
+ export function workingDaysBetween(start, end, config = DEFAULT_WORKING_HOURS) {
206
+ if (end < start)
207
+ return 0;
208
+ let count = 0;
209
+ const current = new Date(start);
210
+ current.setHours(0, 0, 0, 0);
211
+ const endDate = new Date(end);
212
+ endDate.setHours(0, 0, 0, 0);
213
+ while (current <= endDate) {
214
+ if (isWorkingDay(current, config)) {
215
+ count++;
216
+ }
217
+ current.setDate(current.getDate() + 1);
218
+ }
219
+ return count;
220
+ }
221
+ /**
222
+ * Check if a date is during work break
223
+ * @param date - date to check
224
+ * @param config - working hours configuration
225
+ */
226
+ export function isBreakTime(date, config = DEFAULT_WORKING_HOURS) {
227
+ if (!isWorkingDay(date, config))
228
+ return false;
229
+ if (!config.breaks || config.breaks.length === 0)
230
+ return false;
231
+ const h = toHourFraction(date);
232
+ for (const b of config.breaks) {
233
+ if (h >= b.start && h < b.end)
234
+ return true;
235
+ }
236
+ return false;
237
+ }
238
+ /**
239
+ * Get the start of the work day for a given date
240
+ * @param date - date to get work start for
241
+ * @param config - working hours configuration
242
+ */
243
+ export function getWorkDayStart(date, config = DEFAULT_WORKING_HOURS) {
244
+ const result = new Date(date);
245
+ result.setHours(config.hours.start, 0, 0, 0);
246
+ return result;
247
+ }
248
+ /**
249
+ * Get the end of the work day for a given date
250
+ * @param date - date to get work end for
251
+ * @param config - working hours configuration
252
+ */
253
+ export function getWorkDayEnd(date, config = DEFAULT_WORKING_HOURS) {
254
+ const result = new Date(date);
255
+ result.setHours(config.hours.end, 0, 0, 0);
256
+ return result;
257
+ }
258
+ /**
259
+ * Get the total working hours per day (excluding breaks)
260
+ * @param config - working hours configuration
261
+ */
262
+ export function getWorkingHoursPerDay(config = DEFAULT_WORKING_HOURS) {
263
+ let hours = config.hours.end - config.hours.start;
264
+ if (config.breaks) {
265
+ for (const b of config.breaks) {
266
+ hours -= (b.end - b.start);
267
+ }
268
+ }
269
+ return hours;
270
+ }