@catbee/utils 2.0.0-next.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.
- package/LICENSE +1 -1
- package/README.md +102 -52
- package/array/index.cjs +215 -74
- package/array/index.d.ts +345 -2
- package/array/index.mjs +201 -74
- package/async/index.cjs +116 -39
- package/async/index.d.ts +292 -2
- package/async/index.mjs +116 -40
- package/cache/index.cjs +2 -2
- package/cache/index.d.ts +156 -2
- package/cache/index.mjs +3 -3
- package/config/index.cjs +80 -66
- package/config/index.d.ts +65 -3
- package/config/index.mjs +77 -65
- package/context-store/index.cjs +2 -3
- package/context-store/index.d.ts +193 -2
- package/context-store/index.mjs +2 -3
- package/crypto/index.cjs +55 -5
- package/crypto/index.d.ts +225 -2
- package/crypto/index.mjs +52 -7
- package/date/index.cjs +676 -2
- package/date/index.d.ts +676 -2
- package/date/index.mjs +665 -3
- package/decorator/index.cjs +2172 -0
- package/{decorators/decorators.utils.d.ts → decorator/index.d.ts} +58 -54
- package/decorator/index.mjs +2131 -0
- package/{dir → directory}/index.cjs +5 -4
- package/{dir/dir.utils.d.ts → directory/index.d.ts} +24 -21
- package/{dir → directory}/index.mjs +5 -4
- package/env/index.cjs +100 -68
- package/env/index.d.ts +391 -2
- package/env/index.mjs +100 -68
- package/exception/index.cjs +1 -1
- package/exception/index.d.ts +233 -2
- package/exception/index.mjs +1 -1
- package/fs/index.cjs +71 -37
- package/fs/index.d.ts +206 -2
- package/fs/index.mjs +65 -35
- package/http-status-codes/index.cjs +1 -1
- package/http-status-codes/index.d.ts +268 -2
- package/http-status-codes/index.mjs +1 -1
- package/id/index.cjs +1 -1
- package/id/index.d.ts +38 -2
- package/id/index.mjs +1 -1
- package/index.cjs +13 -13
- package/index.d.ts +5 -5
- package/index.mjs +5 -5
- package/logger/index.cjs +13 -15
- package/logger/index.d.ts +190 -2
- package/logger/index.mjs +14 -16
- package/middleware/index.cjs +1 -1
- package/middleware/index.d.ts +104 -2
- package/middleware/index.mjs +1 -1
- package/object/index.cjs +379 -0
- package/{obj/obj.utils.d.ts → object/index.d.ts} +73 -33
- package/object/index.mjs +360 -0
- package/package.json +41 -23
- package/performance/index.cjs +4 -4
- package/performance/index.d.ts +139 -2
- package/performance/index.mjs +4 -4
- package/request/index.cjs +37 -25
- package/request/index.d.ts +242 -3
- package/request/index.mjs +37 -25
- package/response/index.cjs +1 -1
- package/response/index.d.ts +319 -3
- package/response/index.mjs +1 -1
- package/server/index.cjs +249 -146
- package/server/index.d.ts +866 -5
- package/server/index.mjs +248 -144
- package/stream/index.cjs +1 -1
- package/stream/index.d.ts +91 -2
- package/stream/index.mjs +1 -1
- package/string/index.cjs +34 -1
- package/string/index.d.ts +146 -2
- package/string/index.mjs +31 -2
- package/type/index.cjs +19 -2
- package/type/index.d.ts +144 -2
- package/type/index.mjs +17 -3
- package/types/index.cjs +1 -1
- package/types/index.d.ts +775 -5
- package/types/index.mjs +1 -1
- package/url/index.cjs +63 -5
- package/url/index.d.ts +200 -2
- package/url/index.mjs +59 -6
- package/{validate → validation}/index.cjs +91 -44
- package/{validate/validate.utils.d.ts → validation/index.d.ts} +33 -24
- package/{validate → validation}/index.mjs +87 -44
- package/array/array.utils.d.ts +0 -191
- package/async/async.utils.d.ts +0 -296
- package/cache/cache.utils.d.ts +0 -176
- package/config/config.d.ts +0 -57
- package/context-store/context-store.utils.d.ts +0 -212
- package/crypto/crypto.utils.d.ts +0 -183
- package/date/date.utils.d.ts +0 -190
- package/decorators/index.cjs +0 -913
- package/decorators/index.d.ts +0 -25
- package/decorators/index.mjs +0 -872
- package/dir/index.d.ts +0 -25
- package/env/env.utils.d.ts +0 -400
- package/exception/exception.utils.d.ts +0 -253
- package/fs/fs.utils.d.ts +0 -196
- package/http-status-codes/http-status-codes.d.ts +0 -289
- package/id/id.utils.d.ts +0 -59
- package/logger/logger.utils.d.ts +0 -210
- package/middleware/middleware.utils.d.ts +0 -123
- package/obj/index.cjs +0 -317
- package/obj/index.d.ts +0 -25
- package/obj/index.mjs +0 -301
- package/performance/performance.utils.d.ts +0 -159
- package/request/request.utils.d.ts +0 -109
- package/response/response.utils.d.ts +0 -186
- package/server/server.builder.d.ts +0 -531
- package/server/server.d.ts +0 -303
- package/stream/stream.utils.d.ts +0 -111
- package/string/string.utils.d.ts +0 -124
- package/type/type.utils.d.ts +0 -129
- package/types/api-response.d.ts +0 -175
- package/types/common.d.ts +0 -148
- package/types/config.d.ts +0 -88
- package/types/server.d.ts +0 -291
- package/url/url.utils.d.ts +0 -164
- package/validate/index.d.ts +0 -25
package/date/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -22,4 +22,678 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Format options for the formatDate function
|
|
27
|
+
*/
|
|
28
|
+
interface DateFormatOptions {
|
|
29
|
+
/** Date format pattern (default: 'yyyy-MM-dd') */
|
|
30
|
+
format?: string;
|
|
31
|
+
/** Locale to use for formatting (default: system locale) */
|
|
32
|
+
locale?: string | string[];
|
|
33
|
+
/** Time zone to use (default: system time zone) */
|
|
34
|
+
timeZone?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Format a date according to the specified format pattern.
|
|
38
|
+
*
|
|
39
|
+
* @param date - Date to format
|
|
40
|
+
* @param options - Formatting options
|
|
41
|
+
* @returns Formatted date string
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Format as ISO date
|
|
46
|
+
* formatDate(new Date(), { format: 'yyyy-MM-dd' }); // '2023-05-15'
|
|
47
|
+
*
|
|
48
|
+
* // Format with time
|
|
49
|
+
* formatDate(new Date(), { format: 'yyyy-MM-dd HH:mm:ss' }); // '2023-05-15 14:30:22'
|
|
50
|
+
*
|
|
51
|
+
* // Format with locale
|
|
52
|
+
* formatDate(new Date(), { format: 'PPPP', locale: 'fr-FR' }); // 'lundi 15 mai 2023'
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare function formatDate(date: Date | number, options?: DateFormatOptions): string;
|
|
56
|
+
/**
|
|
57
|
+
* Format a date as relative time (e.g., "5 minutes ago", "in 3 days").
|
|
58
|
+
*
|
|
59
|
+
* @param date - Date to format
|
|
60
|
+
* @param now - Reference date (default: current time)
|
|
61
|
+
* @param locale - Locale to use for formatting
|
|
62
|
+
* @returns Formatted relative time string
|
|
63
|
+
*/
|
|
64
|
+
declare function formatRelativeTime(date: Date | number, now?: Date | number, locale?: string | string[]): string;
|
|
65
|
+
/**
|
|
66
|
+
* Parse a date string or timestamp into a Date object.
|
|
67
|
+
*
|
|
68
|
+
* @param input - Date string or timestamp to parse
|
|
69
|
+
* @param fallback - Fallback date if parsing fails
|
|
70
|
+
* @returns Parsed Date object or fallback
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* parseDate('2023-05-15'); // Date object for May 15, 2023
|
|
75
|
+
* parseDate('invalid', new Date()); // Returns current date as fallback
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare function parseDate(input: string | number, fallback?: Date): Date | null;
|
|
79
|
+
/**
|
|
80
|
+
* Calculate the difference between two dates in the specified unit.
|
|
81
|
+
*
|
|
82
|
+
* @param date1 - First date
|
|
83
|
+
* @param date2 - Second date (default: current time)
|
|
84
|
+
* @param unit - Unit of time for the difference
|
|
85
|
+
* @returns Difference in the specified unit
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // Get difference in days
|
|
90
|
+
* dateDiff(new Date('2023-05-15'), new Date('2023-05-10'), 'days'); // 5
|
|
91
|
+
*
|
|
92
|
+
* // Get difference in hours
|
|
93
|
+
* dateDiff(new Date('2023-05-15T10:00:00'), new Date('2023-05-15T06:00:00'), 'hours'); // 4
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
declare function dateDiff(date1: Date | number, date2?: Date | number, unit?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years'): number;
|
|
97
|
+
/**
|
|
98
|
+
* Add a specified amount of time to a date.
|
|
99
|
+
*
|
|
100
|
+
* @param date - Base date
|
|
101
|
+
* @param amount - Amount to add (can be negative)
|
|
102
|
+
* @param unit - Unit of time to add
|
|
103
|
+
* @returns New date with the addition
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* // Add 5 days
|
|
108
|
+
* addToDate(new Date('2023-05-15'), 5, 'days'); // Date for May 20, 2023
|
|
109
|
+
*
|
|
110
|
+
* // Subtract 2 hours
|
|
111
|
+
* addToDate(new Date('2023-05-15T10:00:00'), -2, 'hours'); // Date for May 15, 2023 08:00:00
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare function addToDate(date: Date | number, amount: number, unit: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years'): Date;
|
|
115
|
+
/**
|
|
116
|
+
* Get the start of a time period containing the specified date.
|
|
117
|
+
*
|
|
118
|
+
* @param date - Date to get the start from
|
|
119
|
+
* @param unit - Time unit
|
|
120
|
+
* @returns Date object representing the start of the time unit
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // Get start of day (midnight)
|
|
125
|
+
* startOf(new Date('2023-05-15T14:30:00'), 'day'); // Date for May 15, 2023 00:00:00
|
|
126
|
+
*
|
|
127
|
+
* // Get start of month
|
|
128
|
+
* startOf(new Date('2023-05-15'), 'month'); // Date for May 1, 2023
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function startOf(date: Date | number, unit: 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'): Date;
|
|
132
|
+
/**
|
|
133
|
+
* Get the end of a time period containing the specified date.
|
|
134
|
+
*
|
|
135
|
+
* @param date - Date to get the end from
|
|
136
|
+
* @param unit - Time unit
|
|
137
|
+
* @returns Date object representing the end of the time unit
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* // Get end of day (23:59:59.999)
|
|
142
|
+
* endOf(new Date('2023-05-15T14:30:00'), 'day'); // Date for May 15, 2023 23:59:59.999
|
|
143
|
+
*
|
|
144
|
+
* // Get end of month
|
|
145
|
+
* endOf(new Date('2023-05-15'), 'month'); // Date for May 31, 2023 23:59:59.999
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
declare function endOf(date: Date | number, unit: 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'): Date;
|
|
149
|
+
/**
|
|
150
|
+
* Check if a date is between two other dates.
|
|
151
|
+
*
|
|
152
|
+
* @param date - Date to check
|
|
153
|
+
* @param start - Start date of the range
|
|
154
|
+
* @param end - End date of the range
|
|
155
|
+
* @param inclusive - Whether the comparison should be inclusive of start/end
|
|
156
|
+
* @returns True if the date is within the range
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const date = new Date('2023-05-15');
|
|
161
|
+
* const start = new Date('2023-05-10');
|
|
162
|
+
* const end = new Date('2023-05-20');
|
|
163
|
+
*
|
|
164
|
+
* isBetween(date, start, end); // true
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
declare function isBetween(date: Date | number, start: Date | number, end: Date | number, inclusive?: boolean): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Check if a year is a leap year.
|
|
170
|
+
*
|
|
171
|
+
* @param year - Year to check (or date object)
|
|
172
|
+
* @returns True if the year is a leap year
|
|
173
|
+
*/
|
|
174
|
+
declare function isLeapYear(year: number | Date): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Get the number of days in a month.
|
|
177
|
+
*
|
|
178
|
+
* @param year - Year
|
|
179
|
+
* @param month - Month (0-11)
|
|
180
|
+
* @returns Number of days in the month
|
|
181
|
+
*/
|
|
182
|
+
declare function daysInMonth(year: number | Date, month?: number): number;
|
|
183
|
+
/**
|
|
184
|
+
* Format a duration given in milliseconds to a human readable string.
|
|
185
|
+
* Examples: 3661000 -> "1h 1m 1s", 90061 -> "1m 30s 61ms"
|
|
186
|
+
*
|
|
187
|
+
* @param {number} ms - Duration in milliseconds
|
|
188
|
+
* @returns {string} Human readable duration
|
|
189
|
+
*/
|
|
190
|
+
declare function formatDuration(ms: number): string;
|
|
191
|
+
/**
|
|
192
|
+
* Parse a duration string or number into milliseconds.
|
|
193
|
+
* Supports formats like: 1y, 2w, 3d, 4h, 5m, 6s, 7ms, 1w2d3h, or plain milliseconds like "60000"
|
|
194
|
+
*
|
|
195
|
+
* @param value - Duration string or number
|
|
196
|
+
* @returns Milliseconds
|
|
197
|
+
*/
|
|
198
|
+
declare function parseDuration(value: string | number): number;
|
|
199
|
+
/**
|
|
200
|
+
* Convert a duration string into a Date object representing the future time.
|
|
201
|
+
*
|
|
202
|
+
* @param input - Duration string (e.g., "5m", "2h", "1d")
|
|
203
|
+
* @returns Date object representing the future time
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* toDateFromNow("5m"); // Date object 5 minutes from now
|
|
208
|
+
* toDateFromNow("2h"); // Date object 2 hours from now
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare function getDateFromDuration(input: string): Date;
|
|
212
|
+
/**
|
|
213
|
+
* Checks if a date is on a weekend (Saturday or Sunday).
|
|
214
|
+
*
|
|
215
|
+
* @param {Date | number} date - The date to check.
|
|
216
|
+
* @returns {boolean} True if weekend.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* isWeekend(new Date('2024-01-06')); // true (Saturday)
|
|
220
|
+
*/
|
|
221
|
+
declare function isWeekend(date: Date | number): boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Checks if a date is today.
|
|
224
|
+
*
|
|
225
|
+
* @param {Date | number} date - The date to check.
|
|
226
|
+
* @returns {boolean} True if today.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* isToday(new Date()); // true
|
|
230
|
+
*/
|
|
231
|
+
declare function isToday(date: Date | number): boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Checks if a date is in the future.
|
|
234
|
+
*
|
|
235
|
+
* @param {Date | number} date - The date to check.
|
|
236
|
+
* @returns {boolean} True if in the future.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* isFuture(new Date('2099-01-01')); // true
|
|
240
|
+
*/
|
|
241
|
+
declare function isFuture(date: Date | number): boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Checks if a date is in the past.
|
|
244
|
+
*
|
|
245
|
+
* @param {Date | number} date - The date to check.
|
|
246
|
+
* @returns {boolean} True if in the past.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* isPast(new Date('2020-01-01')); // true
|
|
250
|
+
*/
|
|
251
|
+
declare function isPast(date: Date | number): boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Adds days to a date.
|
|
254
|
+
*
|
|
255
|
+
* @param {Date | number} date - The base date.
|
|
256
|
+
* @param {number} days - Number of days to add (can be negative).
|
|
257
|
+
* @returns {Date} New date with days added.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* addDays(new Date('2024-01-15'), 7); // 2024-01-22
|
|
261
|
+
*/
|
|
262
|
+
declare function addDays(date: Date | number, days: number): Date;
|
|
263
|
+
/**
|
|
264
|
+
* Adds months to a date.
|
|
265
|
+
*
|
|
266
|
+
* @param {Date | number} date - The base date.
|
|
267
|
+
* @param {number} months - Number of months to add (can be negative).
|
|
268
|
+
* @returns {Date} New date with months added.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* addMonths(new Date('2024-01-31'), 1); // 2024-02-29 (leap year)
|
|
272
|
+
*/
|
|
273
|
+
declare function addMonths(date: Date | number, months: number): Date;
|
|
274
|
+
/**
|
|
275
|
+
* Adds years to a date.
|
|
276
|
+
*
|
|
277
|
+
* @param {Date | number} date - The base date.
|
|
278
|
+
* @param {number} years - Number of years to add (can be negative).
|
|
279
|
+
* @returns {Date} New date with years added.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* addYears(new Date('2024-01-15'), 5); // 2029-01-15
|
|
283
|
+
*/
|
|
284
|
+
declare function addYears(date: Date | number, years: number): Date;
|
|
285
|
+
/**
|
|
286
|
+
* Gets the quarter of the year for a date (1-4).
|
|
287
|
+
*
|
|
288
|
+
* @param {Date | number} date - The date.
|
|
289
|
+
* @returns {1 | 2 | 3 | 4} Quarter number.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* quarterOf(new Date('2024-03-15')); // 1
|
|
293
|
+
* quarterOf(new Date('2024-07-15')); // 3
|
|
294
|
+
*/
|
|
295
|
+
declare function quarterOf(date: Date | number): 1 | 2 | 3 | 4;
|
|
296
|
+
/**
|
|
297
|
+
* Gets the ISO week number of the year for a date.
|
|
298
|
+
*
|
|
299
|
+
* @param {Date | number} date - The date.
|
|
300
|
+
* @returns {number} Week number (1-53).
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* weekOfYear(new Date('2024-01-15')); // 3
|
|
304
|
+
*/
|
|
305
|
+
declare function weekOfYear(date: Date | number): number;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* DateBuilder class for fluent date manipulation and building.
|
|
309
|
+
* Provides a chainable API similar to Java's date builders.
|
|
310
|
+
* All methods return a new instance, making it immutable.
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* // Create a date builder
|
|
315
|
+
* const date = new DateBuilder()
|
|
316
|
+
* .year(2024)
|
|
317
|
+
* .month(5)
|
|
318
|
+
* .day(15)
|
|
319
|
+
* .hour(14)
|
|
320
|
+
* .minute(30)
|
|
321
|
+
* .build();
|
|
322
|
+
*
|
|
323
|
+
* // Chain operations
|
|
324
|
+
* const nextWeek = new DateBuilder()
|
|
325
|
+
* .addDays(7)
|
|
326
|
+
* .startOfDay()
|
|
327
|
+
* .build();
|
|
328
|
+
*
|
|
329
|
+
* // Use with existing date
|
|
330
|
+
* const modified = DateBuilder.from(new Date())
|
|
331
|
+
* .addMonths(2)
|
|
332
|
+
* .endOfMonth()
|
|
333
|
+
* .format('yyyy-MM-dd');
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
declare class DateBuilder {
|
|
337
|
+
private readonly date;
|
|
338
|
+
/**
|
|
339
|
+
* Creates a new DateBuilder instance.
|
|
340
|
+
* @param date - Initial date (default: current date/time)
|
|
341
|
+
*/
|
|
342
|
+
constructor(date?: Date | number | string);
|
|
343
|
+
/**
|
|
344
|
+
* Create a DateBuilder from an existing date.
|
|
345
|
+
* @param date - Date to build from
|
|
346
|
+
*/
|
|
347
|
+
static from(date: Date | number | string): DateBuilder;
|
|
348
|
+
/**
|
|
349
|
+
* Create a DateBuilder for the current moment.
|
|
350
|
+
*/
|
|
351
|
+
static now(): DateBuilder;
|
|
352
|
+
/**
|
|
353
|
+
* Create a DateBuilder for a specific date.
|
|
354
|
+
* @param year - Year
|
|
355
|
+
* @param month - Month (1-12, not 0-11)
|
|
356
|
+
* @param day - Day of month
|
|
357
|
+
* @param hour - Hour (default: 0)
|
|
358
|
+
* @param minute - Minute (default: 0)
|
|
359
|
+
* @param second - Second (default: 0)
|
|
360
|
+
* @param millisecond - Millisecond (default: 0)
|
|
361
|
+
*/
|
|
362
|
+
static of(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millisecond?: number): DateBuilder;
|
|
363
|
+
/**
|
|
364
|
+
* Parse a date string into a DateBuilder.
|
|
365
|
+
* @param dateString - Date string to parse
|
|
366
|
+
*/
|
|
367
|
+
static parse(dateString: string): DateBuilder;
|
|
368
|
+
/**
|
|
369
|
+
* Create a DateBuilder from a duration string (e.g., "5m", "2h", "1d" from now).
|
|
370
|
+
* @param duration - Duration string
|
|
371
|
+
*/
|
|
372
|
+
static fromDuration(duration: string): DateBuilder;
|
|
373
|
+
/**
|
|
374
|
+
* Clone this DateBuilder instance.
|
|
375
|
+
*/
|
|
376
|
+
clone(): DateBuilder;
|
|
377
|
+
/**
|
|
378
|
+
* Set the year.
|
|
379
|
+
* @param year - Year to set
|
|
380
|
+
*/
|
|
381
|
+
year(year: number): DateBuilder;
|
|
382
|
+
/**
|
|
383
|
+
* Set the month (1-12, not 0-11).
|
|
384
|
+
* @param month - Month to set (1-12)
|
|
385
|
+
*/
|
|
386
|
+
month(month: number): DateBuilder;
|
|
387
|
+
/**
|
|
388
|
+
* Set the day of the month.
|
|
389
|
+
* @param day - Day to set
|
|
390
|
+
*/
|
|
391
|
+
day(day: number): DateBuilder;
|
|
392
|
+
/**
|
|
393
|
+
* Set the hour.
|
|
394
|
+
* @param hour - Hour to set
|
|
395
|
+
*/
|
|
396
|
+
hour(hour: number): DateBuilder;
|
|
397
|
+
/**
|
|
398
|
+
* Set the minute.
|
|
399
|
+
* @param minute - Minute to set
|
|
400
|
+
*/
|
|
401
|
+
minute(minute: number): DateBuilder;
|
|
402
|
+
/**
|
|
403
|
+
* Set the second.
|
|
404
|
+
* @param second - Second to set
|
|
405
|
+
*/
|
|
406
|
+
second(second: number): DateBuilder;
|
|
407
|
+
/**
|
|
408
|
+
* Set the millisecond.
|
|
409
|
+
* @param millisecond - Millisecond to set
|
|
410
|
+
*/
|
|
411
|
+
millisecond(millisecond: number): DateBuilder;
|
|
412
|
+
/**
|
|
413
|
+
* Add years to the date.
|
|
414
|
+
* @param years - Number of years to add (can be negative)
|
|
415
|
+
*/
|
|
416
|
+
addYears(years: number): DateBuilder;
|
|
417
|
+
/**
|
|
418
|
+
* Add months to the date.
|
|
419
|
+
* @param months - Number of months to add (can be negative)
|
|
420
|
+
*/
|
|
421
|
+
addMonths(months: number): DateBuilder;
|
|
422
|
+
/**
|
|
423
|
+
* Add days to the date.
|
|
424
|
+
* @param days - Number of days to add (can be negative)
|
|
425
|
+
*/
|
|
426
|
+
addDays(days: number): DateBuilder;
|
|
427
|
+
/**
|
|
428
|
+
* Add hours to the date.
|
|
429
|
+
* @param hours - Number of hours to add (can be negative)
|
|
430
|
+
*/
|
|
431
|
+
addHours(hours: number): DateBuilder;
|
|
432
|
+
/**
|
|
433
|
+
* Add minutes to the date.
|
|
434
|
+
* @param minutes - Number of minutes to add (can be negative)
|
|
435
|
+
*/
|
|
436
|
+
addMinutes(minutes: number): DateBuilder;
|
|
437
|
+
/**
|
|
438
|
+
* Add seconds to the date.
|
|
439
|
+
* @param seconds - Number of seconds to add (can be negative)
|
|
440
|
+
*/
|
|
441
|
+
addSeconds(seconds: number): DateBuilder;
|
|
442
|
+
/**
|
|
443
|
+
* Add milliseconds to the date.
|
|
444
|
+
* @param milliseconds - Number of milliseconds to add (can be negative)
|
|
445
|
+
*/
|
|
446
|
+
addMilliseconds(milliseconds: number): DateBuilder;
|
|
447
|
+
/**
|
|
448
|
+
* Subtract years from the date.
|
|
449
|
+
* @param years - Number of years to subtract
|
|
450
|
+
*/
|
|
451
|
+
subtractYears(years: number): DateBuilder;
|
|
452
|
+
/**
|
|
453
|
+
* Subtract months from the date.
|
|
454
|
+
* @param months - Number of months to subtract
|
|
455
|
+
*/
|
|
456
|
+
subtractMonths(months: number): DateBuilder;
|
|
457
|
+
/**
|
|
458
|
+
* Subtract days from the date.
|
|
459
|
+
* @param days - Number of days to subtract
|
|
460
|
+
*/
|
|
461
|
+
subtractDays(days: number): DateBuilder;
|
|
462
|
+
/**
|
|
463
|
+
* Subtract hours from the date.
|
|
464
|
+
* @param hours - Number of hours to subtract
|
|
465
|
+
*/
|
|
466
|
+
subtractHours(hours: number): DateBuilder;
|
|
467
|
+
/**
|
|
468
|
+
* Subtract minutes from the date.
|
|
469
|
+
* @param minutes - Number of minutes to subtract
|
|
470
|
+
*/
|
|
471
|
+
subtractMinutes(minutes: number): DateBuilder;
|
|
472
|
+
/**
|
|
473
|
+
* Subtract seconds from the date.
|
|
474
|
+
* @param seconds - Number of seconds to subtract
|
|
475
|
+
*/
|
|
476
|
+
subtractSeconds(seconds: number): DateBuilder;
|
|
477
|
+
/**
|
|
478
|
+
* Set to the start of the second.
|
|
479
|
+
*/
|
|
480
|
+
startOfSecond(): DateBuilder;
|
|
481
|
+
/**
|
|
482
|
+
* Set to the start of the minute.
|
|
483
|
+
*/
|
|
484
|
+
startOfMinute(): DateBuilder;
|
|
485
|
+
/**
|
|
486
|
+
* Set to the start of the hour.
|
|
487
|
+
*/
|
|
488
|
+
startOfHour(): DateBuilder;
|
|
489
|
+
/**
|
|
490
|
+
* Set to the start of the day (midnight).
|
|
491
|
+
*/
|
|
492
|
+
startOfDay(): DateBuilder;
|
|
493
|
+
/**
|
|
494
|
+
* Set to the start of the week (Sunday).
|
|
495
|
+
*/
|
|
496
|
+
startOfWeek(): DateBuilder;
|
|
497
|
+
/**
|
|
498
|
+
* Set to the start of the month.
|
|
499
|
+
*/
|
|
500
|
+
startOfMonth(): DateBuilder;
|
|
501
|
+
/**
|
|
502
|
+
* Set to the start of the quarter.
|
|
503
|
+
*/
|
|
504
|
+
startOfQuarter(): DateBuilder;
|
|
505
|
+
/**
|
|
506
|
+
* Set to the start of the year.
|
|
507
|
+
*/
|
|
508
|
+
startOfYear(): DateBuilder;
|
|
509
|
+
/**
|
|
510
|
+
* Set to the end of the second.
|
|
511
|
+
*/
|
|
512
|
+
endOfSecond(): DateBuilder;
|
|
513
|
+
/**
|
|
514
|
+
* Set to the end of the minute.
|
|
515
|
+
*/
|
|
516
|
+
endOfMinute(): DateBuilder;
|
|
517
|
+
/**
|
|
518
|
+
* Set to the end of the hour.
|
|
519
|
+
*/
|
|
520
|
+
endOfHour(): DateBuilder;
|
|
521
|
+
/**
|
|
522
|
+
* Set to the end of the day (23:59:59.999).
|
|
523
|
+
*/
|
|
524
|
+
endOfDay(): DateBuilder;
|
|
525
|
+
/**
|
|
526
|
+
* Set to the end of the week (Saturday).
|
|
527
|
+
*/
|
|
528
|
+
endOfWeek(): DateBuilder;
|
|
529
|
+
/**
|
|
530
|
+
* Set to the end of the month.
|
|
531
|
+
*/
|
|
532
|
+
endOfMonth(): DateBuilder;
|
|
533
|
+
/**
|
|
534
|
+
* Set to the end of the quarter.
|
|
535
|
+
*/
|
|
536
|
+
endOfQuarter(): DateBuilder;
|
|
537
|
+
/**
|
|
538
|
+
* Set to the end of the year.
|
|
539
|
+
*/
|
|
540
|
+
endOfYear(): DateBuilder;
|
|
541
|
+
/**
|
|
542
|
+
* Check if the date is before another date.
|
|
543
|
+
* @param other - Date to compare with
|
|
544
|
+
*/
|
|
545
|
+
isBefore(other: Date | DateBuilder): boolean;
|
|
546
|
+
/**
|
|
547
|
+
* Check if the date is after another date.
|
|
548
|
+
* @param other - Date to compare with
|
|
549
|
+
*/
|
|
550
|
+
isAfter(other: Date | DateBuilder): boolean;
|
|
551
|
+
/**
|
|
552
|
+
* Check if the date is the same as another date.
|
|
553
|
+
* @param other - Date to compare with
|
|
554
|
+
*/
|
|
555
|
+
isSame(other: Date | DateBuilder): boolean;
|
|
556
|
+
/**
|
|
557
|
+
* Check if the date is between two dates.
|
|
558
|
+
* @param start - Start date
|
|
559
|
+
* @param end - End date
|
|
560
|
+
* @param inclusive - Whether to include boundaries
|
|
561
|
+
*/
|
|
562
|
+
isBetween(start: Date | DateBuilder, end: Date | DateBuilder, inclusive?: boolean): boolean;
|
|
563
|
+
/**
|
|
564
|
+
* Check if the date is today.
|
|
565
|
+
*/
|
|
566
|
+
isToday(): boolean;
|
|
567
|
+
/**
|
|
568
|
+
* Check if the date is in the future.
|
|
569
|
+
*/
|
|
570
|
+
isFuture(): boolean;
|
|
571
|
+
/**
|
|
572
|
+
* Check if the date is in the past.
|
|
573
|
+
*/
|
|
574
|
+
isPast(): boolean;
|
|
575
|
+
/**
|
|
576
|
+
* Check if the date is on a weekend.
|
|
577
|
+
*/
|
|
578
|
+
isWeekend(): boolean;
|
|
579
|
+
/**
|
|
580
|
+
* Check if the year is a leap year.
|
|
581
|
+
*/
|
|
582
|
+
isLeapYear(): boolean;
|
|
583
|
+
/**
|
|
584
|
+
* Get the year.
|
|
585
|
+
*/
|
|
586
|
+
getYear(): number;
|
|
587
|
+
/**
|
|
588
|
+
* Get the month (1-12, not 0-11).
|
|
589
|
+
*/
|
|
590
|
+
getMonth(): number;
|
|
591
|
+
/**
|
|
592
|
+
* Get the day of the month.
|
|
593
|
+
*/
|
|
594
|
+
getDay(): number;
|
|
595
|
+
/**
|
|
596
|
+
* Get the day of the week (0-6, Sunday is 0).
|
|
597
|
+
*/
|
|
598
|
+
getDayOfWeek(): number;
|
|
599
|
+
/**
|
|
600
|
+
* Get the hour.
|
|
601
|
+
*/
|
|
602
|
+
getHour(): number;
|
|
603
|
+
/**
|
|
604
|
+
* Get the minute.
|
|
605
|
+
*/
|
|
606
|
+
getMinute(): number;
|
|
607
|
+
/**
|
|
608
|
+
* Get the second.
|
|
609
|
+
*/
|
|
610
|
+
getSecond(): number;
|
|
611
|
+
/**
|
|
612
|
+
* Get the millisecond.
|
|
613
|
+
*/
|
|
614
|
+
getMillisecond(): number;
|
|
615
|
+
/**
|
|
616
|
+
* Get the quarter (1-4).
|
|
617
|
+
*/
|
|
618
|
+
getQuarter(): 1 | 2 | 3 | 4;
|
|
619
|
+
/**
|
|
620
|
+
* Get the ISO week number.
|
|
621
|
+
*/
|
|
622
|
+
getWeekOfYear(): number;
|
|
623
|
+
/**
|
|
624
|
+
* Get the number of days in the current month.
|
|
625
|
+
*/
|
|
626
|
+
getDaysInMonth(): number;
|
|
627
|
+
/**
|
|
628
|
+
* Get the Unix timestamp in milliseconds.
|
|
629
|
+
*/
|
|
630
|
+
getTime(): number;
|
|
631
|
+
/**
|
|
632
|
+
* Get the Unix timestamp in seconds.
|
|
633
|
+
*/
|
|
634
|
+
getUnixTimestamp(): number;
|
|
635
|
+
/**
|
|
636
|
+
* Calculate the difference from another date.
|
|
637
|
+
* @param other - Date to compare with
|
|
638
|
+
* @param unit - Unit of time
|
|
639
|
+
*/
|
|
640
|
+
diff(other: Date | DateBuilder, unit?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years'): number;
|
|
641
|
+
/**
|
|
642
|
+
* Get the difference from now.
|
|
643
|
+
* @param unit - Unit of time
|
|
644
|
+
*/
|
|
645
|
+
diffFromNow(unit?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years'): number;
|
|
646
|
+
/**
|
|
647
|
+
* Format the date.
|
|
648
|
+
* @param options - Formatting options
|
|
649
|
+
*/
|
|
650
|
+
format(options?: DateFormatOptions | string): string;
|
|
651
|
+
/**
|
|
652
|
+
* Format as relative time (e.g., "5 minutes ago").
|
|
653
|
+
* @param locale - Locale for formatting
|
|
654
|
+
*/
|
|
655
|
+
formatRelative(locale?: string | string[]): string;
|
|
656
|
+
/**
|
|
657
|
+
* Format as ISO 8601 string.
|
|
658
|
+
*/
|
|
659
|
+
toISOString(): string;
|
|
660
|
+
/**
|
|
661
|
+
* Format as UTC string.
|
|
662
|
+
*/
|
|
663
|
+
toUTCString(): string;
|
|
664
|
+
/**
|
|
665
|
+
* Format as date string.
|
|
666
|
+
*/
|
|
667
|
+
toDateString(): string;
|
|
668
|
+
/**
|
|
669
|
+
* Format as time string.
|
|
670
|
+
*/
|
|
671
|
+
toTimeString(): string;
|
|
672
|
+
/**
|
|
673
|
+
* Format as locale string.
|
|
674
|
+
*/
|
|
675
|
+
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
676
|
+
/**
|
|
677
|
+
* Convert to JSON string.
|
|
678
|
+
*/
|
|
679
|
+
toJSON(): string;
|
|
680
|
+
/**
|
|
681
|
+
* Build and return the Date object.
|
|
682
|
+
*/
|
|
683
|
+
build(): Date;
|
|
684
|
+
/**
|
|
685
|
+
* Get the Date object (alias for build).
|
|
686
|
+
*/
|
|
687
|
+
toDate(): Date;
|
|
688
|
+
/**
|
|
689
|
+
* Get the internal Date object value.
|
|
690
|
+
*/
|
|
691
|
+
valueOf(): number;
|
|
692
|
+
/**
|
|
693
|
+
* Convert to string.
|
|
694
|
+
*/
|
|
695
|
+
toString(): string;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export { DateBuilder, addDays, addMonths, addToDate, addYears, dateDiff, daysInMonth, endOf, formatDate, formatDuration, formatRelativeTime, getDateFromDuration, isBetween, isFuture, isLeapYear, isPast, isToday, isWeekend, parseDate, parseDuration, quarterOf, startOf, weekOfYear };
|
|
699
|
+
export type { DateFormatOptions };
|