ts-time-utils 0.0.1 → 1.1.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 (100) hide show
  1. package/README.md +590 -1
  2. package/dist/age.d.ts +1 -10
  3. package/dist/age.d.ts.map +1 -1
  4. package/dist/calculate.d.ts.map +1 -1
  5. package/dist/calculate.js +24 -10
  6. package/dist/constants.d.ts +2 -21
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/constants.js +12 -13
  9. package/dist/countdown.d.ts +217 -0
  10. package/dist/countdown.d.ts.map +1 -0
  11. package/dist/countdown.js +298 -0
  12. package/dist/dateRange.d.ts +266 -0
  13. package/dist/dateRange.d.ts.map +1 -0
  14. package/dist/dateRange.js +433 -0
  15. package/dist/duration.d.ts +171 -0
  16. package/dist/duration.d.ts.map +1 -0
  17. package/dist/duration.js +382 -0
  18. package/dist/esm/age.d.ts +1 -10
  19. package/dist/esm/age.d.ts.map +1 -1
  20. package/dist/esm/calculate.d.ts.map +1 -1
  21. package/dist/esm/calculate.js +24 -10
  22. package/dist/esm/constants.d.ts +2 -21
  23. package/dist/esm/constants.d.ts.map +1 -1
  24. package/dist/esm/constants.js +12 -13
  25. package/dist/esm/countdown.d.ts +217 -0
  26. package/dist/esm/countdown.d.ts.map +1 -0
  27. package/dist/esm/countdown.js +298 -0
  28. package/dist/esm/dateRange.d.ts +266 -0
  29. package/dist/esm/dateRange.d.ts.map +1 -0
  30. package/dist/esm/dateRange.js +433 -0
  31. package/dist/esm/duration.d.ts +171 -0
  32. package/dist/esm/duration.d.ts.map +1 -0
  33. package/dist/esm/duration.js +382 -0
  34. package/dist/esm/format.d.ts.map +1 -1
  35. package/dist/esm/index.d.ts +14 -6
  36. package/dist/esm/index.d.ts.map +1 -1
  37. package/dist/esm/index.js +16 -0
  38. package/dist/esm/interval.d.ts +3 -6
  39. package/dist/esm/interval.d.ts.map +1 -1
  40. package/dist/esm/locale.d.ts +94 -0
  41. package/dist/esm/locale.d.ts.map +1 -0
  42. package/dist/esm/locale.js +1087 -0
  43. package/dist/esm/naturalLanguage.d.ts +107 -0
  44. package/dist/esm/naturalLanguage.d.ts.map +1 -0
  45. package/dist/esm/naturalLanguage.js +344 -0
  46. package/dist/esm/performance.d.ts +2 -9
  47. package/dist/esm/performance.d.ts.map +1 -1
  48. package/dist/esm/performance.js +7 -8
  49. package/dist/esm/rangePresets.d.ts +7 -8
  50. package/dist/esm/rangePresets.d.ts.map +1 -1
  51. package/dist/esm/rangePresets.js +11 -9
  52. package/dist/esm/recurrence.d.ts +149 -0
  53. package/dist/esm/recurrence.d.ts.map +1 -0
  54. package/dist/esm/recurrence.js +404 -0
  55. package/dist/esm/serialize.d.ts +73 -0
  56. package/dist/esm/serialize.d.ts.map +1 -0
  57. package/dist/esm/serialize.js +365 -0
  58. package/dist/esm/timezone.d.ts +2 -6
  59. package/dist/esm/timezone.d.ts.map +1 -1
  60. package/dist/esm/timezone.js +1 -1
  61. package/dist/esm/types.d.ts +250 -0
  62. package/dist/esm/types.d.ts.map +1 -0
  63. package/dist/esm/types.js +25 -0
  64. package/dist/esm/workingHours.d.ts +4 -13
  65. package/dist/esm/workingHours.d.ts.map +1 -1
  66. package/dist/esm/workingHours.js +3 -1
  67. package/dist/format.d.ts.map +1 -1
  68. package/dist/index.d.ts +14 -6
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +16 -0
  71. package/dist/interval.d.ts +3 -6
  72. package/dist/interval.d.ts.map +1 -1
  73. package/dist/locale.d.ts +94 -0
  74. package/dist/locale.d.ts.map +1 -0
  75. package/dist/locale.js +1087 -0
  76. package/dist/naturalLanguage.d.ts +107 -0
  77. package/dist/naturalLanguage.d.ts.map +1 -0
  78. package/dist/naturalLanguage.js +344 -0
  79. package/dist/performance.d.ts +2 -9
  80. package/dist/performance.d.ts.map +1 -1
  81. package/dist/performance.js +7 -8
  82. package/dist/rangePresets.d.ts +7 -8
  83. package/dist/rangePresets.d.ts.map +1 -1
  84. package/dist/rangePresets.js +11 -9
  85. package/dist/recurrence.d.ts +149 -0
  86. package/dist/recurrence.d.ts.map +1 -0
  87. package/dist/recurrence.js +404 -0
  88. package/dist/serialize.d.ts +73 -0
  89. package/dist/serialize.d.ts.map +1 -0
  90. package/dist/serialize.js +365 -0
  91. package/dist/timezone.d.ts +2 -6
  92. package/dist/timezone.d.ts.map +1 -1
  93. package/dist/timezone.js +1 -1
  94. package/dist/types.d.ts +250 -0
  95. package/dist/types.d.ts.map +1 -0
  96. package/dist/types.js +25 -0
  97. package/dist/workingHours.d.ts +4 -13
  98. package/dist/workingHours.d.ts.map +1 -1
  99. package/dist/workingHours.js +3 -1
  100. package/package.json +67 -3
@@ -0,0 +1,171 @@
1
+ import type { DurationInput, DurationComparison } from './types.js';
2
+ /**
3
+ * Represents a duration of time with arithmetic and conversion capabilities
4
+ */
5
+ export declare class Duration {
6
+ private readonly _milliseconds;
7
+ constructor(input: number | DurationInput | string);
8
+ /**
9
+ * Create Duration from milliseconds
10
+ */
11
+ static fromMilliseconds(ms: number): Duration;
12
+ /**
13
+ * Create Duration from seconds
14
+ */
15
+ static fromSeconds(seconds: number): Duration;
16
+ /**
17
+ * Create Duration from minutes
18
+ */
19
+ static fromMinutes(minutes: number): Duration;
20
+ /**
21
+ * Create Duration from hours
22
+ */
23
+ static fromHours(hours: number): Duration;
24
+ /**
25
+ * Create Duration from days
26
+ */
27
+ static fromDays(days: number): Duration;
28
+ /**
29
+ * Create Duration from weeks
30
+ */
31
+ static fromWeeks(weeks: number): Duration;
32
+ /**
33
+ * Create Duration from a string (e.g., "1h 30m", "2.5 hours", "90 seconds")
34
+ */
35
+ static fromString(str: string): Duration;
36
+ /**
37
+ * Create Duration between two dates
38
+ */
39
+ static between(start: Date, end: Date): Duration;
40
+ /**
41
+ * Get duration in milliseconds
42
+ */
43
+ get milliseconds(): number;
44
+ /**
45
+ * Get duration in seconds
46
+ */
47
+ get seconds(): number;
48
+ /**
49
+ * Get duration in minutes
50
+ */
51
+ get minutes(): number;
52
+ /**
53
+ * Get duration in hours
54
+ */
55
+ get hours(): number;
56
+ /**
57
+ * Get duration in days
58
+ */
59
+ get days(): number;
60
+ /**
61
+ * Get duration in weeks
62
+ */
63
+ get weeks(): number;
64
+ /**
65
+ * Add another duration
66
+ */
67
+ add(other: Duration | number | DurationInput): Duration;
68
+ /**
69
+ * Subtract another duration
70
+ */
71
+ subtract(other: Duration | number | DurationInput): Duration;
72
+ /**
73
+ * Multiply duration by a factor
74
+ */
75
+ multiply(factor: number): Duration;
76
+ /**
77
+ * Divide duration by a factor
78
+ */
79
+ divide(factor: number): Duration;
80
+ /**
81
+ * Get absolute duration (always positive)
82
+ */
83
+ abs(): Duration;
84
+ /**
85
+ * Negate duration
86
+ */
87
+ negate(): Duration;
88
+ /**
89
+ * Check if duration equals another
90
+ */
91
+ equals(other: Duration | number): boolean;
92
+ /**
93
+ * Check if duration is greater than another
94
+ */
95
+ greaterThan(other: Duration | number): boolean;
96
+ /**
97
+ * Check if duration is less than another
98
+ */
99
+ lessThan(other: Duration | number): boolean;
100
+ /**
101
+ * Compare with another duration (-1, 0, 1)
102
+ */
103
+ compareTo(other: Duration): DurationComparison;
104
+ /**
105
+ * Check if duration is zero
106
+ */
107
+ isZero(): boolean;
108
+ /**
109
+ * Check if duration is positive
110
+ */
111
+ isPositive(): boolean;
112
+ /**
113
+ * Check if duration is negative
114
+ */
115
+ isNegative(): boolean;
116
+ /**
117
+ * Convert to human-readable string
118
+ */
119
+ toString(): string;
120
+ /**
121
+ * Convert to detailed object representation
122
+ */
123
+ toObject(): Required<DurationInput>;
124
+ /**
125
+ * Convert to JSON representation
126
+ */
127
+ toJSON(): number;
128
+ /**
129
+ * Create Duration from JSON
130
+ */
131
+ static fromJSON(ms: number): Duration;
132
+ private calculateMilliseconds;
133
+ private parseString;
134
+ private normalizeToDuration;
135
+ }
136
+ /**
137
+ * Create a new Duration instance
138
+ */
139
+ export declare function createDuration(input: number | DurationInput | string): Duration;
140
+ /**
141
+ * Check if a value is a valid duration
142
+ */
143
+ export declare function isValidDuration(value: any): value is Duration;
144
+ /**
145
+ * Parse duration from various formats
146
+ */
147
+ export declare function parseDurationString(input: string | number | DurationInput): Duration;
148
+ /**
149
+ * Format duration to human-readable string
150
+ */
151
+ export declare function formatDurationString(duration: Duration | number, options?: {
152
+ long?: boolean;
153
+ precision?: number;
154
+ }): string;
155
+ /**
156
+ * Get the maximum duration from an array
157
+ */
158
+ export declare function maxDuration(...durations: Duration[]): Duration | null;
159
+ /**
160
+ * Get the minimum duration from an array
161
+ */
162
+ export declare function minDuration(...durations: Duration[]): Duration | null;
163
+ /**
164
+ * Sum multiple durations
165
+ */
166
+ export declare function sumDurations(...durations: Duration[]): Duration;
167
+ /**
168
+ * Get average duration from an array
169
+ */
170
+ export declare function averageDuration(...durations: Duration[]): Duration | null;
171
+ //# sourceMappingURL=duration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/duration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAgB,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAElF;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,MAAM;IAUlD;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ;IAI7C;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ;IAI7C;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ;IAI7C;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ;IAIzC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;IAIvC;;OAEG;IACH,M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,CAKzE"}
@@ -0,0 +1,382 @@
1
+ import { MILLISECONDS_PER_SECOND, MILLISECONDS_PER_MINUTE, MILLISECONDS_PER_HOUR, MILLISECONDS_PER_DAY, MILLISECONDS_PER_WEEK } from './constants.js';
2
+ /**
3
+ * Represents a duration of time with arithmetic and conversion capabilities
4
+ */
5
+ export class Duration {
6
+ constructor(input) {
7
+ if (typeof input === 'number') {
8
+ this._milliseconds = input;
9
+ }
10
+ else if (typeof input === 'string') {
11
+ this._milliseconds = this.parseString(input);
12
+ }
13
+ else {
14
+ this._milliseconds = this.calculateMilliseconds(input);
15
+ }
16
+ }
17
+ /**
18
+ * Create Duration from milliseconds
19
+ */
20
+ static fromMilliseconds(ms) {
21
+ return new Duration(ms);
22
+ }
23
+ /**
24
+ * Create Duration from seconds
25
+ */
26
+ static fromSeconds(seconds) {
27
+ return new Duration(seconds * MILLISECONDS_PER_SECOND);
28
+ }
29
+ /**
30
+ * Create Duration from minutes
31
+ */
32
+ static fromMinutes(minutes) {
33
+ return new Duration(minutes * MILLISECONDS_PER_MINUTE);
34
+ }
35
+ /**
36
+ * Create Duration from hours
37
+ */
38
+ static fromHours(hours) {
39
+ return new Duration(hours * MILLISECONDS_PER_HOUR);
40
+ }
41
+ /**
42
+ * Create Duration from days
43
+ */
44
+ static fromDays(days) {
45
+ return new Duration(days * MILLISECONDS_PER_DAY);
46
+ }
47
+ /**
48
+ * Create Duration from weeks
49
+ */
50
+ static fromWeeks(weeks) {
51
+ return new Duration(weeks * MILLISECONDS_PER_WEEK);
52
+ }
53
+ /**
54
+ * Create Duration from a string (e.g., "1h 30m", "2.5 hours", "90 seconds")
55
+ */
56
+ static fromString(str) {
57
+ return new Duration(str);
58
+ }
59
+ /**
60
+ * Create Duration between two dates
61
+ */
62
+ static between(start, end) {
63
+ return new Duration(Math.abs(end.getTime() - start.getTime()));
64
+ }
65
+ /**
66
+ * Get duration in milliseconds
67
+ */
68
+ get milliseconds() {
69
+ return this._milliseconds;
70
+ }
71
+ /**
72
+ * Get duration in seconds
73
+ */
74
+ get seconds() {
75
+ return this._milliseconds / MILLISECONDS_PER_SECOND;
76
+ }
77
+ /**
78
+ * Get duration in minutes
79
+ */
80
+ get minutes() {
81
+ return this._milliseconds / MILLISECONDS_PER_MINUTE;
82
+ }
83
+ /**
84
+ * Get duration in hours
85
+ */
86
+ get hours() {
87
+ return this._milliseconds / MILLISECONDS_PER_HOUR;
88
+ }
89
+ /**
90
+ * Get duration in days
91
+ */
92
+ get days() {
93
+ return this._milliseconds / MILLISECONDS_PER_DAY;
94
+ }
95
+ /**
96
+ * Get duration in weeks
97
+ */
98
+ get weeks() {
99
+ return this._milliseconds / MILLISECONDS_PER_WEEK;
100
+ }
101
+ /**
102
+ * Add another duration
103
+ */
104
+ add(other) {
105
+ const otherDuration = this.normalizeToDuration(other);
106
+ return new Duration(this._milliseconds + otherDuration._milliseconds);
107
+ }
108
+ /**
109
+ * Subtract another duration
110
+ */
111
+ subtract(other) {
112
+ const otherDuration = this.normalizeToDuration(other);
113
+ return new Duration(Math.max(0, this._milliseconds - otherDuration._milliseconds));
114
+ }
115
+ /**
116
+ * Multiply duration by a factor
117
+ */
118
+ multiply(factor) {
119
+ return new Duration(this._milliseconds * factor);
120
+ }
121
+ /**
122
+ * Divide duration by a factor
123
+ */
124
+ divide(factor) {
125
+ if (factor === 0) {
126
+ throw new Error('Cannot divide duration by zero');
127
+ }
128
+ return new Duration(this._milliseconds / factor);
129
+ }
130
+ /**
131
+ * Get absolute duration (always positive)
132
+ */
133
+ abs() {
134
+ return new Duration(Math.abs(this._milliseconds));
135
+ }
136
+ /**
137
+ * Negate duration
138
+ */
139
+ negate() {
140
+ return new Duration(-this._milliseconds);
141
+ }
142
+ /**
143
+ * Check if duration equals another
144
+ */
145
+ equals(other) {
146
+ const otherMs = typeof other === 'number' ? other : other._milliseconds;
147
+ return Math.abs(this._milliseconds - otherMs) < 1; // Allow for floating point precision
148
+ }
149
+ /**
150
+ * Check if duration is greater than another
151
+ */
152
+ greaterThan(other) {
153
+ const otherMs = typeof other === 'number' ? other : other._milliseconds;
154
+ return this._milliseconds > otherMs;
155
+ }
156
+ /**
157
+ * Check if duration is less than another
158
+ */
159
+ lessThan(other) {
160
+ const otherMs = typeof other === 'number' ? other : other._milliseconds;
161
+ return this._milliseconds < otherMs;
162
+ }
163
+ /**
164
+ * Compare with another duration (-1, 0, 1)
165
+ */
166
+ compareTo(other) {
167
+ if (this._milliseconds < other._milliseconds)
168
+ return -1;
169
+ if (this._milliseconds > other._milliseconds)
170
+ return 1;
171
+ return 0;
172
+ }
173
+ /**
174
+ * Check if duration is zero
175
+ */
176
+ isZero() {
177
+ return Math.abs(this._milliseconds) < 1;
178
+ }
179
+ /**
180
+ * Check if duration is positive
181
+ */
182
+ isPositive() {
183
+ return this._milliseconds > 0;
184
+ }
185
+ /**
186
+ * Check if duration is negative
187
+ */
188
+ isNegative() {
189
+ return this._milliseconds < 0;
190
+ }
191
+ /**
192
+ * Convert to human-readable string
193
+ */
194
+ toString() {
195
+ if (this.isZero())
196
+ return '0ms';
197
+ const parts = [];
198
+ let remaining = Math.abs(this._milliseconds);
199
+ const units = [
200
+ { name: 'd', value: MILLISECONDS_PER_DAY },
201
+ { name: 'h', value: MILLISECONDS_PER_HOUR },
202
+ { name: 'm', value: MILLISECONDS_PER_MINUTE },
203
+ { name: 's', value: MILLISECONDS_PER_SECOND },
204
+ { name: 'ms', value: 1 }
205
+ ];
206
+ for (const unit of units) {
207
+ if (remaining >= unit.value) {
208
+ const count = Math.floor(remaining / unit.value);
209
+ parts.push(`${count}${unit.name}`);
210
+ remaining %= unit.value;
211
+ }
212
+ }
213
+ const result = parts.join(' ');
214
+ return this._milliseconds < 0 ? `-${result}` : result;
215
+ }
216
+ /**
217
+ * Convert to detailed object representation
218
+ */
219
+ toObject() {
220
+ const ms = Math.abs(this._milliseconds);
221
+ const days = Math.floor(ms / MILLISECONDS_PER_DAY);
222
+ const hours = Math.floor((ms % MILLISECONDS_PER_DAY) / MILLISECONDS_PER_HOUR);
223
+ const minutes = Math.floor((ms % MILLISECONDS_PER_HOUR) / MILLISECONDS_PER_MINUTE);
224
+ const seconds = Math.floor((ms % MILLISECONDS_PER_MINUTE) / MILLISECONDS_PER_SECOND);
225
+ const milliseconds = ms % MILLISECONDS_PER_SECOND;
226
+ return {
227
+ years: 0, // Years/months require complex calendar calculations
228
+ months: 0,
229
+ weeks: Math.floor(days / 7),
230
+ days: days,
231
+ hours,
232
+ minutes,
233
+ seconds,
234
+ milliseconds
235
+ };
236
+ }
237
+ /**
238
+ * Convert to JSON representation
239
+ */
240
+ toJSON() {
241
+ return this._milliseconds;
242
+ }
243
+ /**
244
+ * Create Duration from JSON
245
+ */
246
+ static fromJSON(ms) {
247
+ return new Duration(ms);
248
+ }
249
+ calculateMilliseconds(input) {
250
+ let total = 0;
251
+ if (input.milliseconds)
252
+ total += input.milliseconds;
253
+ if (input.seconds)
254
+ total += input.seconds * MILLISECONDS_PER_SECOND;
255
+ if (input.minutes)
256
+ total += input.minutes * MILLISECONDS_PER_MINUTE;
257
+ if (input.hours)
258
+ total += input.hours * MILLISECONDS_PER_HOUR;
259
+ if (input.days)
260
+ total += input.days * MILLISECONDS_PER_DAY;
261
+ if (input.weeks)
262
+ total += input.weeks * MILLISECONDS_PER_WEEK;
263
+ // Approximate conversions for months and years
264
+ if (input.months)
265
+ total += input.months * MILLISECONDS_PER_DAY * 30.44; // Average month
266
+ if (input.years)
267
+ total += input.years * MILLISECONDS_PER_DAY * 365.25; // Average year
268
+ return total;
269
+ }
270
+ parseString(str) {
271
+ const normalized = str.toLowerCase().trim();
272
+ // Handle simple formats like "1000", "1000ms"
273
+ if (/^\d+(?:ms)?$/.test(normalized)) {
274
+ return parseInt(normalized.replace('ms', ''));
275
+ }
276
+ // Handle complex formats like "1h 30m 45s"
277
+ const patterns = [
278
+ { regex: /(\d+(?:\.\d+)?)\s*y(?:ears?)?(?!\w)/g, multiplier: MILLISECONDS_PER_DAY * 365.25 },
279
+ { regex: /(\d+(?:\.\d+)?)\s*mo(?:nths?)?(?!\w)/g, multiplier: MILLISECONDS_PER_DAY * 30.44 },
280
+ { regex: /(\d+(?:\.\d+)?)\s*w(?:eeks?)?(?!\w)/g, multiplier: MILLISECONDS_PER_WEEK },
281
+ { regex: /(\d+(?:\.\d+)?)\s*d(?:ays?)?(?!\w)/g, multiplier: MILLISECONDS_PER_DAY },
282
+ { regex: /(\d+(?:\.\d+)?)\s*h(?:ours?)?(?!\w)/g, multiplier: MILLISECONDS_PER_HOUR },
283
+ { regex: /(\d+(?:\.\d+)?)\s*min(?:utes?)?(?!\w)/g, multiplier: MILLISECONDS_PER_MINUTE },
284
+ { regex: /(\d+(?:\.\d+)?)\s*m(?!s|o)(?!\w)/g, multiplier: MILLISECONDS_PER_MINUTE },
285
+ { regex: /(\d+(?:\.\d+)?)\s*s(?:ec(?:onds?)?)?(?!\w)/g, multiplier: MILLISECONDS_PER_SECOND },
286
+ { regex: /(\d+(?:\.\d+)?)\s*ms(?!\w)/g, multiplier: 1 }
287
+ ];
288
+ let total = 0;
289
+ let hasMatch = false;
290
+ for (const pattern of patterns) {
291
+ let match;
292
+ while ((match = pattern.regex.exec(normalized)) !== null) {
293
+ total += parseFloat(match[1]) * pattern.multiplier;
294
+ hasMatch = true;
295
+ }
296
+ pattern.regex.lastIndex = 0; // Reset regex
297
+ }
298
+ if (!hasMatch) {
299
+ throw new Error(`Invalid duration format: ${str}`);
300
+ }
301
+ return total;
302
+ }
303
+ normalizeToDuration(input) {
304
+ if (input instanceof Duration) {
305
+ return input;
306
+ }
307
+ return new Duration(input);
308
+ }
309
+ }
310
+ /**
311
+ * Create a new Duration instance
312
+ */
313
+ export function createDuration(input) {
314
+ return new Duration(input);
315
+ }
316
+ /**
317
+ * Check if a value is a valid duration
318
+ */
319
+ export function isValidDuration(value) {
320
+ return value instanceof Duration;
321
+ }
322
+ /**
323
+ * Parse duration from various formats
324
+ */
325
+ export function parseDurationString(input) {
326
+ return new Duration(input);
327
+ }
328
+ /**
329
+ * Format duration to human-readable string
330
+ */
331
+ export function formatDurationString(duration, options) {
332
+ const d = typeof duration === 'number' ? new Duration(duration) : duration;
333
+ if (options?.long) {
334
+ const obj = d.toObject();
335
+ const parts = [];
336
+ const units = [
337
+ { key: 'days', singular: 'day', plural: 'days' },
338
+ { key: 'hours', singular: 'hour', plural: 'hours' },
339
+ { key: 'minutes', singular: 'minute', plural: 'minutes' },
340
+ { key: 'seconds', singular: 'second', plural: 'seconds' }
341
+ ];
342
+ for (const unit of units) {
343
+ const value = obj[unit.key];
344
+ if (value > 0) {
345
+ parts.push(`${value} ${value === 1 ? unit.singular : unit.plural}`);
346
+ }
347
+ }
348
+ return parts.length > 0 ? parts.join(', ') : '0 seconds';
349
+ }
350
+ return d.toString();
351
+ }
352
+ /**
353
+ * Get the maximum duration from an array
354
+ */
355
+ export function maxDuration(...durations) {
356
+ if (durations.length === 0)
357
+ return null;
358
+ return durations.reduce((max, current) => current.greaterThan(max) ? current : max);
359
+ }
360
+ /**
361
+ * Get the minimum duration from an array
362
+ */
363
+ export function minDuration(...durations) {
364
+ if (durations.length === 0)
365
+ return null;
366
+ return durations.reduce((min, current) => current.lessThan(min) ? current : min);
367
+ }
368
+ /**
369
+ * Sum multiple durations
370
+ */
371
+ export function sumDurations(...durations) {
372
+ return durations.reduce((sum, current) => sum.add(current), new Duration(0));
373
+ }
374
+ /**
375
+ * Get average duration from an array
376
+ */
377
+ export function averageDuration(...durations) {
378
+ if (durations.length === 0)
379
+ return null;
380
+ const sum = sumDurations(...durations);
381
+ return sum.divide(durations.length);
382
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CA2E9E;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CA+CvE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,KAAK,GAAG,KAAK,GAAG,KAAa,GAAG,MAAM,CAcpF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAyDtD"}
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,aAAa,EACd,MAAM,gBAAgB,CAAC;AAGxB;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CA2E9E;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CA+CvE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,KAAK,GAAG,KAAK,GAAG,KAAa,GAAG,MAAM,CAcpF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAyDtD"}
@@ -5,13 +5,21 @@
5
5
  export { formatDuration, timeAgo, formatTime, parseDuration } from './format.js';
6
6
  export { differenceInUnits, addTime, subtractTime, startOf, endOf, isBetween, businessDaysBetween } from './calculate.js';
7
7
  export { isValidDate, isLeapYear, isPast, isFuture, isToday, isYesterday, isTomorrow, isSameDay, isWeekend, isWeekday, isValidTimeString, isValidISOString } from './validate.js';
8
- export { calculateAge, getAgeInUnits, getLifeStage, getNextBirthday, getDaysUntilBirthday, isBirthday, type AgeResult } from './age.js';
8
+ export { calculateAge, getAgeInUnits, getLifeStage, getNextBirthday, getDaysUntilBirthday, isBirthday } from './age.js';
9
9
  export { getWeekNumber, getWeekOfMonth, getQuarter, getDayOfYear, getWeeksInYear, getDaysInMonth, getDaysInYear, getEaster, getMonthsInYear, getDaysInMonthArray, getWeekdaysInMonth, getFirstDayOfMonth, getLastDayOfMonth, getFirstDayOfYear, getLastDayOfYear } from './calendar.js';
10
10
  export { parseDate, parseRelativeDate, parseTimeAgo, parseCustomFormat, parseManyFormats } from './parse.js';
11
- export { sleep, timeout, debounce, throttle, retry, createStopwatch, measureTime, measureAsync, benchmark, Stopwatch, type BenchmarkResult } from './performance.js';
12
- export { createInterval, isValidInterval, intervalDuration, intervalContains, intervalsOverlap, intervalIntersection, mergeIntervals, subtractInterval, splitIntervalByDay, totalIntervalCoverage, normalizeIntervals, type Interval } from './interval.js';
13
- export { getTimezoneOffset, formatInTimeZone, getZonedTime, convertDateToZone, isValidTimeZone, COMMON_TIMEZONES, getLocalOffset, compareZoneOffsets, reinterpretAsZone, type ZonedTime } from './timezone.js';
14
- export { DEFAULT_WORKING_HOURS, isWorkingDay, isWorkingTime, nextWorkingTime, workingTimeBetween, addWorkingHours, type WorkingHoursConfig } from './workingHours.js';
15
- export { today, yesterday, tomorrow, lastNDays, nextNDays, thisWeek, lastWeek, nextWeek, thisMonth, lastMonth, nextMonth, thisYear, lastYear, nextYear, rollingWindowDays, quarterRange, lastQuarter, nextQuarter, RANGE_PRESETS, type DateRange } from './rangePresets.js';
11
+ export { sleep, timeout, debounce, throttle, retry, createStopwatch, measureTime, measureAsync, benchmark, Stopwatch } from './performance.js';
12
+ export { createInterval, isValidInterval, intervalDuration, intervalContains, intervalsOverlap, intervalIntersection, mergeIntervals, subtractInterval, splitIntervalByDay, totalIntervalCoverage, normalizeIntervals } from './interval.js';
13
+ export { getTimezoneOffset, formatInTimeZone, getZonedTime, convertDateToZone, isValidTimeZone, COMMON_TIMEZONES, getLocalOffset, compareZoneOffsets, reinterpretAsZone } from './timezone.js';
14
+ export { DEFAULT_WORKING_HOURS, isWorkingDay, isWorkingTime, nextWorkingTime, workingTimeBetween, addWorkingHours } from './workingHours.js';
15
+ export { today, yesterday, tomorrow, lastNDays, nextNDays, thisWeek, lastWeek, nextWeek, thisMonth, lastMonth, nextMonth, thisYear, lastYear, nextYear, rollingWindowDays, quarterRange, lastQuarter, nextQuarter, RANGE_PRESETS } from './rangePresets.js';
16
+ export { Duration, createDuration, isValidDuration, parseDurationString, formatDurationString, maxDuration, minDuration, sumDurations, averageDuration } from './duration.js';
17
+ export { serializeDate, deserializeDate, createDateReviver, createDateReplacer, parseISOString, toEpochTimestamp, fromEpochTimestamp, createEpochTimestamp, toDateObject, fromDateObject, isValidISODateString, isValidEpochTimestamp, cloneDate, datesEqual, now, parseJSONWithDates, stringifyWithDates } from './serialize.js';
18
+ export { registerLocale, getLocaleConfig, getSupportedLocales, formatRelativeTime, formatDateLocale, formatTimeLocale, formatDateTimeLocale, getMonthNames, getDayNames, getFirstDayOfWeek, isLocaleSupported, getBestMatchingLocale, detectLocale, convertRelativeTime, detectLocaleFromRelativeTime, convertFormatPattern, convertFormattedDate, convertRelativeTimeArray, compareLocaleFormats } from './locale.js';
19
+ export { createRecurrence, getNextOccurrence, getOccurrencesBetween, isRecurrenceDate, isValidRecurrenceRule, recurrenceToString } from './recurrence.js';
20
+ export { createCountdown, getRemainingTime, formatCountdown, isExpired, getProgressPercentage, getTimeUntil, createDeadline, type Countdown, type RemainingTime, type CountdownOptions } from './countdown.js';
21
+ export { dateRangeOverlap, hasOverlappingRanges, mergeDateRanges, findGaps, splitRange, containsDate, getIntersection, getUnion, subtractRange, getRangeDuration, expandRange, shrinkRange, rangeContains, sortRanges } from './dateRange.js';
22
+ export { parseNaturalDate, parseRelativePhrase, extractDatesFromText, suggestDateFromContext, type NaturalParseOptions, type ExtractedDate } from './naturalLanguage.js';
16
23
  export { MILLISECONDS_PER_SECOND, MILLISECONDS_PER_MINUTE, MILLISECONDS_PER_HOUR, MILLISECONDS_PER_DAY, MILLISECONDS_PER_WEEK, MILLISECONDS_PER_MONTH, MILLISECONDS_PER_YEAR, SECONDS_PER_MINUTE, SECONDS_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_WEEK, type TimeUnit, type FormatOptions } from './constants.js';
24
+ export type { DateInput, DateRange, ParseOptions, WorkingHoursConfig, AgeResult, ZonedTime, Interval, BenchmarkResult, RecurrencePattern, RecurrenceRule, RecurrenceFrequency, LocaleFormatOptions, BusinessConfig, DateValidator, DateTransformer, TimeUtilsError, ParseError, ValidationError, DurationUnit, DurationInput, DurationComparison, SerializationOptions, DateObject, EpochTimestamp, SupportedLocale, LocaleConfig, RelativeTimeOptions, RelativeTimeUnit } from './types.js';
17
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,cAAc,EACd,OAAO,EACP,UAAU,EACV,aAAa,EACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,iBAAiB,EACjB,OAAO,EACP,YAAY,EACZ,OAAO,EACP,KAAK,EACL,SAAS,EACT,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,eAAe,EACf,oBAAoB,EACpB,UAAU,EACV,KAAK,SAAS,EACf,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,aAAa,EACb,cAAc,EACd,UAAU,EACV,YAAY,EACZ,cAAc,EACd,cAAc,EACd,aAAa,EACb,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAGvB,OAAO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KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,cAAc,EACd,OAAO,EACP,UAAU,EACV,aAAa,EACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,iBAAiB,EACjB,OAAO,EACP,YAAY,EACZ,OAAO,EACP,KAAK,EACL,SAAS,EACT,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,eAAe,EACf,oBAAoB,EACpB,UAAU,EACX,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,aAAa,EACb,cAAc,EACd,UAAU,EACV,YAAY,EACZ,cAAc,EACd,cAAc,EACd,aAAa,EACb,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,kB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B,gBAAgB,EACjB,MAAM,YAAY,CAAC"}
package/dist/esm/index.js CHANGED
@@ -24,5 +24,21 @@ export { getTimezoneOffset, formatInTimeZone, getZonedTime, convertDateToZone, i
24
24
  export { DEFAULT_WORKING_HOURS, isWorkingDay, isWorkingTime, nextWorkingTime, workingTimeBetween, addWorkingHours } from './workingHours.js';
25
25
  // Range preset utilities
26
26
  export { today, yesterday, tomorrow, lastNDays, nextNDays, thisWeek, lastWeek, nextWeek, thisMonth, lastMonth, nextMonth, thisYear, lastYear, nextYear, rollingWindowDays, quarterRange, lastQuarter, nextQuarter, RANGE_PRESETS } from './rangePresets.js';
27
+ // Duration utilities
28
+ export { Duration, createDuration, isValidDuration, parseDurationString, formatDurationString, maxDuration, minDuration, sumDurations, averageDuration } from './duration.js';
29
+ // Serialization utilities
30
+ export { serializeDate, deserializeDate, createDateReviver, createDateReplacer, parseISOString, toEpochTimestamp, fromEpochTimestamp, createEpochTimestamp, toDateObject, fromDateObject, isValidISODateString, isValidEpochTimestamp, cloneDate, datesEqual, now, parseJSONWithDates, stringifyWithDates } from './serialize.js';
31
+ // Locale utilities
32
+ export { registerLocale, getLocaleConfig, getSupportedLocales, formatRelativeTime, formatDateLocale, formatTimeLocale, formatDateTimeLocale, getMonthNames, getDayNames, getFirstDayOfWeek, isLocaleSupported, getBestMatchingLocale, detectLocale,
33
+ // Conversion utilities
34
+ convertRelativeTime, detectLocaleFromRelativeTime, convertFormatPattern, convertFormattedDate, convertRelativeTimeArray, compareLocaleFormats } from './locale.js';
35
+ // Recurrence utilities
36
+ export { createRecurrence, getNextOccurrence, getOccurrencesBetween, isRecurrenceDate, isValidRecurrenceRule, recurrenceToString } from './recurrence.js';
37
+ // Countdown utilities
38
+ export { createCountdown, getRemainingTime, formatCountdown, isExpired, getProgressPercentage, getTimeUntil, createDeadline } from './countdown.js';
39
+ // Date range utilities
40
+ export { dateRangeOverlap, hasOverlappingRanges, mergeDateRanges, findGaps, splitRange, containsDate, getIntersection, getUnion, subtractRange, getRangeDuration, expandRange, shrinkRange, rangeContains, sortRanges } from './dateRange.js';
41
+ // Natural language parsing utilities
42
+ export { parseNaturalDate, parseRelativePhrase, extractDatesFromText, suggestDateFromContext } from './naturalLanguage.js';
27
43
  // Constants and types
28
44
  export { MILLISECONDS_PER_SECOND, MILLISECONDS_PER_MINUTE, MILLISECONDS_PER_HOUR, MILLISECONDS_PER_DAY, MILLISECONDS_PER_WEEK, MILLISECONDS_PER_MONTH, MILLISECONDS_PER_YEAR, SECONDS_PER_MINUTE, SECONDS_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_WEEK } from './constants.js';
@@ -1,18 +1,15 @@
1
1
  /**
2
2
  * Interval utilities: operations on time intervals [start, end)
3
3
  */
4
- export interface Interval {
5
- start: Date;
6
- end: Date;
7
- }
4
+ import type { Interval, DateInput } from './types.js';
8
5
  /** Create an interval ensuring start <= end */
9
- export declare function createInterval(start: Date | string | number, end: Date | string | number): Interval | null;
6
+ export declare function createInterval(start: DateInput, end: DateInput): Interval | null;
10
7
  /** Validate an object is a proper interval */
11
8
  export declare function isValidInterval(i: any): i is Interval;
12
9
  /** Duration of interval in ms */
13
10
  export declare function intervalDuration(i: Interval): number;
14
11
  /** Whether interval contains date (inclusive start, exclusive end) */
15
- export declare function intervalContains(i: Interval, date: Date | number): boolean;
12
+ export declare function intervalContains(i: Interval, date: DateInput): boolean;
16
13
  /** Whether two intervals overlap */
17
14
  export declare function intervalsOverlap(a: Interval, b: Interval): boolean;
18
15
  /** Intersection of two intervals, or null */
@@ -1 +1 @@
1
- {"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../../src/interval.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,IAAI,CAAC;IACZ,GAAG,EAAE,IAAI,CAAC;CACX;AAED,+CAA+C;AAC/C,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,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