ts-time-utils 2.0.0 → 3.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.
- package/README.md +110 -1
- package/dist/chain.d.ts +269 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +422 -0
- package/dist/esm/chain.d.ts +269 -0
- package/dist/esm/chain.d.ts.map +1 -0
- package/dist/esm/chain.js +422 -0
- package/dist/esm/holidays.d.ts +62 -0
- package/dist/esm/holidays.d.ts.map +1 -0
- package/dist/esm/holidays.js +793 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/plugins.d.ts +129 -0
- package/dist/esm/plugins.d.ts.map +1 -0
- package/dist/esm/plugins.js +173 -0
- package/dist/holidays.d.ts +62 -0
- package/dist/holidays.d.ts.map +1 -0
- package/dist/holidays.js +793 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/plugins.d.ts +129 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +173 -0
- package/package.json +30 -10
package/dist/chain.js
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent chain API for ts-time-utils
|
|
3
|
+
*
|
|
4
|
+
* Provides a chainable interface for date operations:
|
|
5
|
+
* ```ts
|
|
6
|
+
* chain(new Date())
|
|
7
|
+
* .add(1, 'day')
|
|
8
|
+
* .startOf('month')
|
|
9
|
+
* .format('YYYY-MM-DD')
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
import { addTime, subtractTime, startOf, endOf, differenceInUnits, isBetween } from './calculate.js';
|
|
13
|
+
import { formatDate, formatDuration, timeAgo, formatTime, formatCalendarDate, formatOrdinal } from './format.js';
|
|
14
|
+
import { isValidDate, isToday, isYesterday, isTomorrow, isPast, isFuture, isWeekend, isWeekday, isSameDay, isSameWeek, isSameMonth, isSameYear, isThisWeek, isThisMonth, isThisYear, isBusinessDay, isLeapYear } from './validate.js';
|
|
15
|
+
/**
|
|
16
|
+
* Immutable chainable date wrapper
|
|
17
|
+
* All transformation methods return a new ChainedDate instance
|
|
18
|
+
*/
|
|
19
|
+
export class ChainedDate {
|
|
20
|
+
constructor(date = new Date()) {
|
|
21
|
+
if (date instanceof Date) {
|
|
22
|
+
this._date = new Date(date.getTime());
|
|
23
|
+
}
|
|
24
|
+
else if (typeof date === 'number') {
|
|
25
|
+
this._date = new Date(date);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this._date = new Date(date);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// ============ Transformations (return new ChainedDate) ============
|
|
32
|
+
/**
|
|
33
|
+
* Add time to the date
|
|
34
|
+
* @example chain(date).add(1, 'day').add(2, 'hours')
|
|
35
|
+
*/
|
|
36
|
+
add(amount, unit) {
|
|
37
|
+
return new ChainedDate(addTime(this._date, amount, unit));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Subtract time from the date
|
|
41
|
+
* @example chain(date).subtract(1, 'week')
|
|
42
|
+
*/
|
|
43
|
+
subtract(amount, unit) {
|
|
44
|
+
return new ChainedDate(subtractTime(this._date, amount, unit));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the start of a time period
|
|
48
|
+
* @example chain(date).startOf('month')
|
|
49
|
+
*/
|
|
50
|
+
startOf(unit) {
|
|
51
|
+
return new ChainedDate(startOf(this._date, unit));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the end of a time period
|
|
55
|
+
* @example chain(date).endOf('day')
|
|
56
|
+
*/
|
|
57
|
+
endOf(unit) {
|
|
58
|
+
return new ChainedDate(endOf(this._date, unit));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Set specific date/time components
|
|
62
|
+
* @example chain(date).set({ year: 2025, month: 1 })
|
|
63
|
+
*/
|
|
64
|
+
set(values) {
|
|
65
|
+
const d = new Date(this._date.getTime());
|
|
66
|
+
if (values.year !== undefined)
|
|
67
|
+
d.setFullYear(values.year);
|
|
68
|
+
if (values.month !== undefined)
|
|
69
|
+
d.setMonth(values.month - 1); // 1-indexed input
|
|
70
|
+
if (values.day !== undefined)
|
|
71
|
+
d.setDate(values.day);
|
|
72
|
+
if (values.hours !== undefined)
|
|
73
|
+
d.setHours(values.hours);
|
|
74
|
+
if (values.minutes !== undefined)
|
|
75
|
+
d.setMinutes(values.minutes);
|
|
76
|
+
if (values.seconds !== undefined)
|
|
77
|
+
d.setSeconds(values.seconds);
|
|
78
|
+
if (values.milliseconds !== undefined)
|
|
79
|
+
d.setMilliseconds(values.milliseconds);
|
|
80
|
+
return new ChainedDate(d);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Clone the ChainedDate
|
|
84
|
+
*/
|
|
85
|
+
clone() {
|
|
86
|
+
return new ChainedDate(this._date);
|
|
87
|
+
}
|
|
88
|
+
// ============ Formatters (return string) ============
|
|
89
|
+
/**
|
|
90
|
+
* Format date using pattern string
|
|
91
|
+
* @example chain(date).format('YYYY-MM-DD') // "2025-01-15"
|
|
92
|
+
*/
|
|
93
|
+
format(pattern) {
|
|
94
|
+
return formatDate(this._date, pattern);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Format time in 12h, 24h, or ISO format
|
|
98
|
+
* @example chain(date).formatTime('12h') // "2:30 PM"
|
|
99
|
+
*/
|
|
100
|
+
formatTime(fmt = '24h') {
|
|
101
|
+
return formatTime(this._date, fmt);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Format as calendar date (Today, Yesterday, Monday, etc.)
|
|
105
|
+
* @example chain(date).calendar() // "Tomorrow"
|
|
106
|
+
*/
|
|
107
|
+
calendar() {
|
|
108
|
+
return formatCalendarDate(this._date);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get relative time string
|
|
112
|
+
* @example chain(pastDate).ago() // "3 hours ago"
|
|
113
|
+
*/
|
|
114
|
+
ago(options) {
|
|
115
|
+
return timeAgo(this._date, options);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get ISO string
|
|
119
|
+
*/
|
|
120
|
+
toISOString() {
|
|
121
|
+
return this._date.toISOString();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get locale string
|
|
125
|
+
*/
|
|
126
|
+
toLocaleString(locale, options) {
|
|
127
|
+
return this._date.toLocaleString(locale, options);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Format day as ordinal
|
|
131
|
+
* @example chain(date).dayOrdinal() // "15th"
|
|
132
|
+
*/
|
|
133
|
+
dayOrdinal() {
|
|
134
|
+
return formatOrdinal(this._date.getDate());
|
|
135
|
+
}
|
|
136
|
+
// ============ Comparisons (return boolean) ============
|
|
137
|
+
/**
|
|
138
|
+
* Check if date is valid
|
|
139
|
+
*/
|
|
140
|
+
isValid() {
|
|
141
|
+
return isValidDate(this._date);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Check if date is today
|
|
145
|
+
*/
|
|
146
|
+
isToday() {
|
|
147
|
+
return isToday(this._date);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Check if date is yesterday
|
|
151
|
+
*/
|
|
152
|
+
isYesterday() {
|
|
153
|
+
return isYesterday(this._date);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Check if date is tomorrow
|
|
157
|
+
*/
|
|
158
|
+
isTomorrow() {
|
|
159
|
+
return isTomorrow(this._date);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Check if date is in the past
|
|
163
|
+
*/
|
|
164
|
+
isPast() {
|
|
165
|
+
return isPast(this._date);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Check if date is in the future
|
|
169
|
+
*/
|
|
170
|
+
isFuture() {
|
|
171
|
+
return isFuture(this._date);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Check if date is a weekend
|
|
175
|
+
*/
|
|
176
|
+
isWeekend() {
|
|
177
|
+
return isWeekend(this._date);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Check if date is a weekday
|
|
181
|
+
*/
|
|
182
|
+
isWeekday() {
|
|
183
|
+
return isWeekday(this._date);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Check if date is in this week
|
|
187
|
+
*/
|
|
188
|
+
isThisWeek() {
|
|
189
|
+
return isThisWeek(this._date);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Check if date is in this month
|
|
193
|
+
*/
|
|
194
|
+
isThisMonth() {
|
|
195
|
+
return isThisMonth(this._date);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Check if date is in this year
|
|
199
|
+
*/
|
|
200
|
+
isThisYear() {
|
|
201
|
+
return isThisYear(this._date);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Check if year is a leap year
|
|
205
|
+
*/
|
|
206
|
+
isLeapYear() {
|
|
207
|
+
return isLeapYear(this._date.getFullYear());
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Check if date is a business day
|
|
211
|
+
*/
|
|
212
|
+
isBusinessDay(holidays) {
|
|
213
|
+
return isBusinessDay(this._date, holidays);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Check if date is same day as another
|
|
217
|
+
*/
|
|
218
|
+
isSameDay(other) {
|
|
219
|
+
return isSameDay(this._date, toDate(other));
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Check if date is same week as another
|
|
223
|
+
*/
|
|
224
|
+
isSameWeek(other) {
|
|
225
|
+
return isSameWeek(this._date, toDate(other));
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Check if date is same month as another
|
|
229
|
+
*/
|
|
230
|
+
isSameMonth(other) {
|
|
231
|
+
return isSameMonth(this._date, toDate(other));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Check if date is same year as another
|
|
235
|
+
*/
|
|
236
|
+
isSameYear(other) {
|
|
237
|
+
return isSameYear(this._date, toDate(other));
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Check if date is before another
|
|
241
|
+
*/
|
|
242
|
+
isBefore(other) {
|
|
243
|
+
return this._date.getTime() < toDate(other).getTime();
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Check if date is after another
|
|
247
|
+
*/
|
|
248
|
+
isAfter(other) {
|
|
249
|
+
return this._date.getTime() > toDate(other).getTime();
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Check if date is between two dates
|
|
253
|
+
*/
|
|
254
|
+
isBetween(start, end, inclusive) {
|
|
255
|
+
return isBetween(this._date, toDate(start), toDate(end), inclusive);
|
|
256
|
+
}
|
|
257
|
+
// ============ Getters (return number) ============
|
|
258
|
+
/**
|
|
259
|
+
* Get difference from another date
|
|
260
|
+
* @example chain(date).diff(other, 'days') // 5
|
|
261
|
+
*/
|
|
262
|
+
diff(other, unit = 'milliseconds', precise = true) {
|
|
263
|
+
return differenceInUnits(this._date, toDate(other), unit, precise);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get the timestamp (milliseconds since epoch)
|
|
267
|
+
*/
|
|
268
|
+
valueOf() {
|
|
269
|
+
return this._date.getTime();
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Get year
|
|
273
|
+
*/
|
|
274
|
+
year() {
|
|
275
|
+
return this._date.getFullYear();
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Get month (1-12)
|
|
279
|
+
*/
|
|
280
|
+
month() {
|
|
281
|
+
return this._date.getMonth() + 1;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Get day of month (1-31)
|
|
285
|
+
*/
|
|
286
|
+
day() {
|
|
287
|
+
return this._date.getDate();
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get day of week (0-6, 0=Sunday)
|
|
291
|
+
*/
|
|
292
|
+
weekday() {
|
|
293
|
+
return this._date.getDay();
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Get hours (0-23)
|
|
297
|
+
*/
|
|
298
|
+
hours() {
|
|
299
|
+
return this._date.getHours();
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Get minutes (0-59)
|
|
303
|
+
*/
|
|
304
|
+
minutes() {
|
|
305
|
+
return this._date.getMinutes();
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Get seconds (0-59)
|
|
309
|
+
*/
|
|
310
|
+
seconds() {
|
|
311
|
+
return this._date.getSeconds();
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Get milliseconds (0-999)
|
|
315
|
+
*/
|
|
316
|
+
milliseconds() {
|
|
317
|
+
return this._date.getMilliseconds();
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Get day of year (1-366)
|
|
321
|
+
*/
|
|
322
|
+
dayOfYear() {
|
|
323
|
+
const start = new Date(this._date.getFullYear(), 0, 0);
|
|
324
|
+
const diff = this._date.getTime() - start.getTime();
|
|
325
|
+
const oneDay = 1000 * 60 * 60 * 24;
|
|
326
|
+
return Math.floor(diff / oneDay);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Get ISO week number (1-53)
|
|
330
|
+
*/
|
|
331
|
+
week() {
|
|
332
|
+
const d = new Date(Date.UTC(this._date.getFullYear(), this._date.getMonth(), this._date.getDate()));
|
|
333
|
+
const dayNum = d.getUTCDay() || 7;
|
|
334
|
+
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
|
335
|
+
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
|
336
|
+
return Math.ceil((((d.getTime() - yearStart.getTime()) / 86400000) + 1) / 7);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Get quarter (1-4)
|
|
340
|
+
*/
|
|
341
|
+
quarter() {
|
|
342
|
+
return Math.floor(this._date.getMonth() / 3) + 1;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Get days in month
|
|
346
|
+
*/
|
|
347
|
+
daysInMonth() {
|
|
348
|
+
return new Date(this._date.getFullYear(), this._date.getMonth() + 1, 0).getDate();
|
|
349
|
+
}
|
|
350
|
+
// ============ Conversion ============
|
|
351
|
+
/**
|
|
352
|
+
* Get the underlying Date object
|
|
353
|
+
*/
|
|
354
|
+
toDate() {
|
|
355
|
+
return new Date(this._date.getTime());
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Get Unix timestamp (seconds)
|
|
359
|
+
*/
|
|
360
|
+
unix() {
|
|
361
|
+
return Math.floor(this._date.getTime() / 1000);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Convert to array [year, month, day, hours, minutes, seconds, ms]
|
|
365
|
+
*/
|
|
366
|
+
toArray() {
|
|
367
|
+
return [
|
|
368
|
+
this._date.getFullYear(),
|
|
369
|
+
this._date.getMonth() + 1,
|
|
370
|
+
this._date.getDate(),
|
|
371
|
+
this._date.getHours(),
|
|
372
|
+
this._date.getMinutes(),
|
|
373
|
+
this._date.getSeconds(),
|
|
374
|
+
this._date.getMilliseconds()
|
|
375
|
+
];
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Convert to object
|
|
379
|
+
*/
|
|
380
|
+
toObject() {
|
|
381
|
+
return {
|
|
382
|
+
year: this._date.getFullYear(),
|
|
383
|
+
month: this._date.getMonth() + 1,
|
|
384
|
+
day: this._date.getDate(),
|
|
385
|
+
hours: this._date.getHours(),
|
|
386
|
+
minutes: this._date.getMinutes(),
|
|
387
|
+
seconds: this._date.getSeconds(),
|
|
388
|
+
milliseconds: this._date.getMilliseconds()
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Helper to convert DateInput to Date
|
|
394
|
+
*/
|
|
395
|
+
function toDate(input) {
|
|
396
|
+
if (input instanceof Date)
|
|
397
|
+
return input;
|
|
398
|
+
return new Date(input);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Create a chainable date wrapper
|
|
402
|
+
* @example
|
|
403
|
+
* chain(new Date()).add(1, 'day').format('YYYY-MM-DD')
|
|
404
|
+
* chain('2025-01-15').startOf('month').toDate()
|
|
405
|
+
* chain().add(1, 'week').isWeekend()
|
|
406
|
+
*/
|
|
407
|
+
export function chain(date) {
|
|
408
|
+
return new ChainedDate(date);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Format a duration in milliseconds
|
|
412
|
+
* Convenience export for use with chain().diff()
|
|
413
|
+
* @example formatMs(chain(a).diff(b)) // "2 days, 3 hours"
|
|
414
|
+
*/
|
|
415
|
+
export function formatMs(ms, options) {
|
|
416
|
+
return formatDuration(ms, options);
|
|
417
|
+
}
|
|
418
|
+
// Initialize plugin system if it's available
|
|
419
|
+
// This allows plugins to extend ChainedDate
|
|
420
|
+
if (typeof globalThis !== 'undefined') {
|
|
421
|
+
globalThis.__chainedDateClass = ChainedDate;
|
|
422
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent chain API for ts-time-utils
|
|
3
|
+
*
|
|
4
|
+
* Provides a chainable interface for date operations:
|
|
5
|
+
* ```ts
|
|
6
|
+
* chain(new Date())
|
|
7
|
+
* .add(1, 'day')
|
|
8
|
+
* .startOf('month')
|
|
9
|
+
* .format('YYYY-MM-DD')
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
import type { TimeUnit, DateInput, FormatOptions } from './types.js';
|
|
13
|
+
/** Units accepted by startOf/endOf */
|
|
14
|
+
type StartOfUnit = 'day' | 'week' | 'month' | 'year' | 'hour' | 'minute';
|
|
15
|
+
/**
|
|
16
|
+
* Immutable chainable date wrapper
|
|
17
|
+
* All transformation methods return a new ChainedDate instance
|
|
18
|
+
*/
|
|
19
|
+
export declare class ChainedDate {
|
|
20
|
+
private readonly _date;
|
|
21
|
+
constructor(date?: DateInput);
|
|
22
|
+
/**
|
|
23
|
+
* Add time to the date
|
|
24
|
+
* @example chain(date).add(1, 'day').add(2, 'hours')
|
|
25
|
+
*/
|
|
26
|
+
add(amount: number, unit: TimeUnit): ChainedDate;
|
|
27
|
+
/**
|
|
28
|
+
* Subtract time from the date
|
|
29
|
+
* @example chain(date).subtract(1, 'week')
|
|
30
|
+
*/
|
|
31
|
+
subtract(amount: number, unit: TimeUnit): ChainedDate;
|
|
32
|
+
/**
|
|
33
|
+
* Get the start of a time period
|
|
34
|
+
* @example chain(date).startOf('month')
|
|
35
|
+
*/
|
|
36
|
+
startOf(unit: StartOfUnit): ChainedDate;
|
|
37
|
+
/**
|
|
38
|
+
* Get the end of a time period
|
|
39
|
+
* @example chain(date).endOf('day')
|
|
40
|
+
*/
|
|
41
|
+
endOf(unit: StartOfUnit): ChainedDate;
|
|
42
|
+
/**
|
|
43
|
+
* Set specific date/time components
|
|
44
|
+
* @example chain(date).set({ year: 2025, month: 1 })
|
|
45
|
+
*/
|
|
46
|
+
set(values: {
|
|
47
|
+
year?: number;
|
|
48
|
+
month?: number;
|
|
49
|
+
day?: number;
|
|
50
|
+
hours?: number;
|
|
51
|
+
minutes?: number;
|
|
52
|
+
seconds?: number;
|
|
53
|
+
milliseconds?: number;
|
|
54
|
+
}): ChainedDate;
|
|
55
|
+
/**
|
|
56
|
+
* Clone the ChainedDate
|
|
57
|
+
*/
|
|
58
|
+
clone(): ChainedDate;
|
|
59
|
+
/**
|
|
60
|
+
* Format date using pattern string
|
|
61
|
+
* @example chain(date).format('YYYY-MM-DD') // "2025-01-15"
|
|
62
|
+
*/
|
|
63
|
+
format(pattern: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Format time in 12h, 24h, or ISO format
|
|
66
|
+
* @example chain(date).formatTime('12h') // "2:30 PM"
|
|
67
|
+
*/
|
|
68
|
+
formatTime(fmt?: '12h' | '24h' | 'iso'): string;
|
|
69
|
+
/**
|
|
70
|
+
* Format as calendar date (Today, Yesterday, Monday, etc.)
|
|
71
|
+
* @example chain(date).calendar() // "Tomorrow"
|
|
72
|
+
*/
|
|
73
|
+
calendar(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Get relative time string
|
|
76
|
+
* @example chain(pastDate).ago() // "3 hours ago"
|
|
77
|
+
*/
|
|
78
|
+
ago(options?: FormatOptions): string;
|
|
79
|
+
/**
|
|
80
|
+
* Get ISO string
|
|
81
|
+
*/
|
|
82
|
+
toISOString(): string;
|
|
83
|
+
/**
|
|
84
|
+
* Get locale string
|
|
85
|
+
*/
|
|
86
|
+
toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string;
|
|
87
|
+
/**
|
|
88
|
+
* Format day as ordinal
|
|
89
|
+
* @example chain(date).dayOrdinal() // "15th"
|
|
90
|
+
*/
|
|
91
|
+
dayOrdinal(): string;
|
|
92
|
+
/**
|
|
93
|
+
* Check if date is valid
|
|
94
|
+
*/
|
|
95
|
+
isValid(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Check if date is today
|
|
98
|
+
*/
|
|
99
|
+
isToday(): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Check if date is yesterday
|
|
102
|
+
*/
|
|
103
|
+
isYesterday(): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Check if date is tomorrow
|
|
106
|
+
*/
|
|
107
|
+
isTomorrow(): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Check if date is in the past
|
|
110
|
+
*/
|
|
111
|
+
isPast(): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Check if date is in the future
|
|
114
|
+
*/
|
|
115
|
+
isFuture(): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Check if date is a weekend
|
|
118
|
+
*/
|
|
119
|
+
isWeekend(): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Check if date is a weekday
|
|
122
|
+
*/
|
|
123
|
+
isWeekday(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Check if date is in this week
|
|
126
|
+
*/
|
|
127
|
+
isThisWeek(): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Check if date is in this month
|
|
130
|
+
*/
|
|
131
|
+
isThisMonth(): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Check if date is in this year
|
|
134
|
+
*/
|
|
135
|
+
isThisYear(): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Check if year is a leap year
|
|
138
|
+
*/
|
|
139
|
+
isLeapYear(): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Check if date is a business day
|
|
142
|
+
*/
|
|
143
|
+
isBusinessDay(holidays?: Date[]): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Check if date is same day as another
|
|
146
|
+
*/
|
|
147
|
+
isSameDay(other: DateInput): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Check if date is same week as another
|
|
150
|
+
*/
|
|
151
|
+
isSameWeek(other: DateInput): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Check if date is same month as another
|
|
154
|
+
*/
|
|
155
|
+
isSameMonth(other: DateInput): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Check if date is same year as another
|
|
158
|
+
*/
|
|
159
|
+
isSameYear(other: DateInput): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Check if date is before another
|
|
162
|
+
*/
|
|
163
|
+
isBefore(other: DateInput): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Check if date is after another
|
|
166
|
+
*/
|
|
167
|
+
isAfter(other: DateInput): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Check if date is between two dates
|
|
170
|
+
*/
|
|
171
|
+
isBetween(start: DateInput, end: DateInput, inclusive?: boolean): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Get difference from another date
|
|
174
|
+
* @example chain(date).diff(other, 'days') // 5
|
|
175
|
+
*/
|
|
176
|
+
diff(other: DateInput, unit?: TimeUnit, precise?: boolean): number;
|
|
177
|
+
/**
|
|
178
|
+
* Get the timestamp (milliseconds since epoch)
|
|
179
|
+
*/
|
|
180
|
+
valueOf(): number;
|
|
181
|
+
/**
|
|
182
|
+
* Get year
|
|
183
|
+
*/
|
|
184
|
+
year(): number;
|
|
185
|
+
/**
|
|
186
|
+
* Get month (1-12)
|
|
187
|
+
*/
|
|
188
|
+
month(): number;
|
|
189
|
+
/**
|
|
190
|
+
* Get day of month (1-31)
|
|
191
|
+
*/
|
|
192
|
+
day(): number;
|
|
193
|
+
/**
|
|
194
|
+
* Get day of week (0-6, 0=Sunday)
|
|
195
|
+
*/
|
|
196
|
+
weekday(): number;
|
|
197
|
+
/**
|
|
198
|
+
* Get hours (0-23)
|
|
199
|
+
*/
|
|
200
|
+
hours(): number;
|
|
201
|
+
/**
|
|
202
|
+
* Get minutes (0-59)
|
|
203
|
+
*/
|
|
204
|
+
minutes(): number;
|
|
205
|
+
/**
|
|
206
|
+
* Get seconds (0-59)
|
|
207
|
+
*/
|
|
208
|
+
seconds(): number;
|
|
209
|
+
/**
|
|
210
|
+
* Get milliseconds (0-999)
|
|
211
|
+
*/
|
|
212
|
+
milliseconds(): number;
|
|
213
|
+
/**
|
|
214
|
+
* Get day of year (1-366)
|
|
215
|
+
*/
|
|
216
|
+
dayOfYear(): number;
|
|
217
|
+
/**
|
|
218
|
+
* Get ISO week number (1-53)
|
|
219
|
+
*/
|
|
220
|
+
week(): number;
|
|
221
|
+
/**
|
|
222
|
+
* Get quarter (1-4)
|
|
223
|
+
*/
|
|
224
|
+
quarter(): number;
|
|
225
|
+
/**
|
|
226
|
+
* Get days in month
|
|
227
|
+
*/
|
|
228
|
+
daysInMonth(): number;
|
|
229
|
+
/**
|
|
230
|
+
* Get the underlying Date object
|
|
231
|
+
*/
|
|
232
|
+
toDate(): Date;
|
|
233
|
+
/**
|
|
234
|
+
* Get Unix timestamp (seconds)
|
|
235
|
+
*/
|
|
236
|
+
unix(): number;
|
|
237
|
+
/**
|
|
238
|
+
* Convert to array [year, month, day, hours, minutes, seconds, ms]
|
|
239
|
+
*/
|
|
240
|
+
toArray(): [number, number, number, number, number, number, number];
|
|
241
|
+
/**
|
|
242
|
+
* Convert to object
|
|
243
|
+
*/
|
|
244
|
+
toObject(): {
|
|
245
|
+
year: number;
|
|
246
|
+
month: number;
|
|
247
|
+
day: number;
|
|
248
|
+
hours: number;
|
|
249
|
+
minutes: number;
|
|
250
|
+
seconds: number;
|
|
251
|
+
milliseconds: number;
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Create a chainable date wrapper
|
|
256
|
+
* @example
|
|
257
|
+
* chain(new Date()).add(1, 'day').format('YYYY-MM-DD')
|
|
258
|
+
* chain('2025-01-15').startOf('month').toDate()
|
|
259
|
+
* chain().add(1, 'week').isWeekend()
|
|
260
|
+
*/
|
|
261
|
+
export declare function chain(date?: DateInput): ChainedDate;
|
|
262
|
+
/**
|
|
263
|
+
* Format a duration in milliseconds
|
|
264
|
+
* Convenience export for use with chain().diff()
|
|
265
|
+
* @example formatMs(chain(a).diff(b)) // "2 days, 3 hours"
|
|
266
|
+
*/
|
|
267
|
+
export declare function formatMs(ms: number, options?: FormatOptions): string;
|
|
268
|
+
export {};
|
|
269
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../src/chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AASrE,sCAAsC;AACtC,KAAK,WAAW,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEzE;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;gBAEjB,IAAI,GAAE,S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