datetick 1.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 +21 -0
- package/README.md +118 -0
- package/commitlint.config.mjs +3 -0
- package/dist/index.d.ts +1227 -0
- package/dist/index.js +2422 -0
- package/dist/index.umd.js +2435 -0
- package/dist/index.umd.min.js +1 -0
- package/junit.xml +311 -0
- package/package.json +145 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1227 @@
|
|
|
1
|
+
type DateUnit = 'millisecond' | 'second' | 'minute' | 'hour' | 'date' | 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
2
|
+
type DateFormatPreset = 'short' | 'medium' | 'long' | 'full' | 'dateOnly' | 'timeOnly' | 'weekdayTime' | 'isoStyle12h' | 'isoStyle24h';
|
|
3
|
+
type DateGettableUnit = DateUnit | 'dayOfYear' | 'isoDay' | 'isoWeek' | 'isoWeekYear' | 'isoWeeksInYear' | 'weekYear' | 'weekday' | 'weeksInYear' | 'daysInMonth';
|
|
4
|
+
type CalendarDiffUnit = 'date' | 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
5
|
+
/**
|
|
6
|
+
* Per-side bound inclusivity for {@link DateTick.isBetween}: `(` / `)` are exclusive, `[` / `]` are inclusive.
|
|
7
|
+
* For example `'[)'` includes the start bound but excludes the end bound.
|
|
8
|
+
*/
|
|
9
|
+
type Inclusivity = '()' | '[]' | '(]' | '[)';
|
|
10
|
+
type DateArray = [
|
|
11
|
+
year: number,
|
|
12
|
+
month: number,
|
|
13
|
+
date: number,
|
|
14
|
+
hour?: number,
|
|
15
|
+
minute?: number,
|
|
16
|
+
second?: number,
|
|
17
|
+
millisecond?: number
|
|
18
|
+
];
|
|
19
|
+
interface DateObject {
|
|
20
|
+
year: number;
|
|
21
|
+
month: number;
|
|
22
|
+
date: number;
|
|
23
|
+
hour?: number;
|
|
24
|
+
minute?: number;
|
|
25
|
+
second?: number;
|
|
26
|
+
millisecond?: number;
|
|
27
|
+
}
|
|
28
|
+
interface DatePartsObject extends Required<DateObject> {
|
|
29
|
+
day: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Anything that can be resolved to a point in time: a native Date, an ISO/parsable string,
|
|
33
|
+
* a Unix timestamp in milliseconds, or another DateTick instance.
|
|
34
|
+
*/
|
|
35
|
+
type DateInput = Date | string | number | DateTick | DateObject | DateArray;
|
|
36
|
+
/**
|
|
37
|
+
* A localized weekday label for a calendar grid header.
|
|
38
|
+
*/
|
|
39
|
+
interface CalendarWeekday {
|
|
40
|
+
day: number;
|
|
41
|
+
isoDay: number;
|
|
42
|
+
long: string;
|
|
43
|
+
short: string;
|
|
44
|
+
narrow: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A single date cell in a calendar month grid.
|
|
48
|
+
*/
|
|
49
|
+
interface CalendarDate {
|
|
50
|
+
value: DateTick;
|
|
51
|
+
isoDate: string;
|
|
52
|
+
formatted: string;
|
|
53
|
+
year: number;
|
|
54
|
+
month: number;
|
|
55
|
+
date: number;
|
|
56
|
+
day: number;
|
|
57
|
+
isoDay: number;
|
|
58
|
+
isCurrentMonth: boolean;
|
|
59
|
+
isToday: boolean;
|
|
60
|
+
isSelected: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Options for calendar month generation.
|
|
64
|
+
*/
|
|
65
|
+
interface CalendarMonthOptions {
|
|
66
|
+
selected?: DateInput | false;
|
|
67
|
+
dateFormat?: string | Intl.DateTimeFormatOptions | ((date: DateTick) => string);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Token patterns used by {@link DateTick.calendar} for calendar-style relative labels.
|
|
71
|
+
*/
|
|
72
|
+
interface CalendarDisplayFormats {
|
|
73
|
+
sameDay?: string | ((date: DateTick) => string);
|
|
74
|
+
nextDay?: string | ((date: DateTick) => string);
|
|
75
|
+
nextWeek?: string | ((date: DateTick) => string);
|
|
76
|
+
lastDay?: string | ((date: DateTick) => string);
|
|
77
|
+
lastWeek?: string | ((date: DateTick) => string);
|
|
78
|
+
sameElse?: string | ((date: DateTick) => string);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Calendar data for rendering a month view.
|
|
82
|
+
*/
|
|
83
|
+
interface CalendarMonth {
|
|
84
|
+
year: number;
|
|
85
|
+
month: number;
|
|
86
|
+
label: string;
|
|
87
|
+
weekdays: CalendarWeekday[];
|
|
88
|
+
days: CalendarDate[];
|
|
89
|
+
weeks: CalendarDate[][];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A bag of calendar components used to construct a Duration.
|
|
93
|
+
*/
|
|
94
|
+
interface DurationInput {
|
|
95
|
+
years?: number;
|
|
96
|
+
months?: number;
|
|
97
|
+
weeks?: number;
|
|
98
|
+
days?: number;
|
|
99
|
+
hours?: number;
|
|
100
|
+
minutes?: number;
|
|
101
|
+
seconds?: number;
|
|
102
|
+
milliseconds?: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Produces the ordinal form of a number (e.g. `1` -> `'1st'` in English, `'1er'` in French). Supplied
|
|
106
|
+
* via the factory to localize `ordinal()` and the `Do`/`wo`/`Wo` tokens, which are English by default.
|
|
107
|
+
*/
|
|
108
|
+
type OrdinalFn = (n: number) => string;
|
|
109
|
+
/**
|
|
110
|
+
* Locale metadata for a {@link DateTick}, resolved through `Intl` — the Day.js `localeData()` equivalent.
|
|
111
|
+
*/
|
|
112
|
+
interface LocaleData {
|
|
113
|
+
/** Long month names, index 0 = January. */
|
|
114
|
+
months(): string[];
|
|
115
|
+
/** Short month names, index 0 = January. */
|
|
116
|
+
monthsShort(): string[];
|
|
117
|
+
/** Long weekday names, index 0 = Sunday. */
|
|
118
|
+
weekdays(): string[];
|
|
119
|
+
/** Short weekday names, index 0 = Sunday. */
|
|
120
|
+
weekdaysShort(): string[];
|
|
121
|
+
/** Narrow (minimal) weekday names, index 0 = Sunday. */
|
|
122
|
+
weekdaysMin(): string[];
|
|
123
|
+
/** The configured first day of the week (0 = Sunday … 6 = Saturday). */
|
|
124
|
+
firstDayOfWeek(): number;
|
|
125
|
+
/** The locale's AM/PM markers. */
|
|
126
|
+
meridiems(): {
|
|
127
|
+
am: string;
|
|
128
|
+
pm: string;
|
|
129
|
+
};
|
|
130
|
+
/** The AM or PM marker for a 0-23 hour (lowercased when `isLowercase`). */
|
|
131
|
+
meridiem(hour: number, isLowercase?: boolean): string;
|
|
132
|
+
/** The ordinal form of a number (e.g. `1` -> `'1st'`). */
|
|
133
|
+
ordinal(n: number): string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Overrides the cutoffs {@link DateTick.timeAgo} uses to step up from one unit to the next. Each value is
|
|
137
|
+
* the largest count of that unit still shown before switching to the next larger unit (e.g. `second: 60`
|
|
138
|
+
* shows seconds up to 59, then minutes). Months use a 30-day approximation and years a 365-day one.
|
|
139
|
+
*/
|
|
140
|
+
interface RelativeTimeThresholds {
|
|
141
|
+
/** Max seconds before switching to minutes (default 60). */
|
|
142
|
+
second?: number;
|
|
143
|
+
/** Max minutes before switching to hours (default 60). */
|
|
144
|
+
minute?: number;
|
|
145
|
+
/** Max hours before switching to days (default 24). */
|
|
146
|
+
hour?: number;
|
|
147
|
+
/** Max days before switching to months (default 30). */
|
|
148
|
+
day?: number;
|
|
149
|
+
/** Max months before switching to years (default 12). */
|
|
150
|
+
month?: number;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Receives live relative-time labels from {@link DateTick.timeAgoLive}.
|
|
154
|
+
*/
|
|
155
|
+
type TimeAgoListener = (value: string) => void;
|
|
156
|
+
/**
|
|
157
|
+
* A dependency-free live relative-time subscription.
|
|
158
|
+
*/
|
|
159
|
+
interface TimeAgoLive {
|
|
160
|
+
subscribe(listener: TimeAgoListener): () => void;
|
|
161
|
+
unsubscribe(): void;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* An immutable length of time, independent of any particular instant.
|
|
166
|
+
*
|
|
167
|
+
* Conversions use fixed ratios (1 month = 30 days, 1 year = 365 days). `humanize()` is locale-aware via `Intl`.
|
|
168
|
+
*
|
|
169
|
+
* @class Duration
|
|
170
|
+
*/
|
|
171
|
+
declare class Duration {
|
|
172
|
+
private readonly _locale;
|
|
173
|
+
private readonly _ms;
|
|
174
|
+
/**
|
|
175
|
+
* Creates a Duration.
|
|
176
|
+
*
|
|
177
|
+
* @param {number | string | DurationInput} value - A millisecond amount, an amount paired with `unit`,
|
|
178
|
+
* an ISO 8601 duration string (e.g. 'P1Y2M10DT2H30M'), or a components object
|
|
179
|
+
* @param {DateUnit} [unit] - The unit when `value` is a number (defaults to milliseconds)
|
|
180
|
+
* @param {string} [locale='en'] - The locale used by `humanize()`
|
|
181
|
+
* @throws {Error} If `value` is a string that is not a valid ISO 8601 duration
|
|
182
|
+
* @memberof Duration
|
|
183
|
+
*/
|
|
184
|
+
constructor(value: number | string | DurationInput, unit?: DateUnit, locale?: string);
|
|
185
|
+
/**
|
|
186
|
+
* Checks whether a value is a Duration instance.
|
|
187
|
+
*
|
|
188
|
+
* @param {unknown} value - The value to check
|
|
189
|
+
* @returns {boolean} True if the value is a Duration
|
|
190
|
+
* @memberof Duration
|
|
191
|
+
*/
|
|
192
|
+
static isDuration(value: unknown): value is Duration;
|
|
193
|
+
/**
|
|
194
|
+
* Returns a new Duration with the given amount added
|
|
195
|
+
*
|
|
196
|
+
* @param {number} value - The amount to add
|
|
197
|
+
* @param {DateUnit} [unit='millisecond'] - The unit of the amount
|
|
198
|
+
* @returns {Duration} The new Duration
|
|
199
|
+
* @memberof Duration
|
|
200
|
+
*/
|
|
201
|
+
add(value: number, unit?: DateUnit): Duration;
|
|
202
|
+
/**
|
|
203
|
+
* The whole duration expressed in a chosen unit.
|
|
204
|
+
*
|
|
205
|
+
* @param {DateUnit} unit - The target unit
|
|
206
|
+
* @returns {number} The duration in that unit
|
|
207
|
+
* @memberof Duration
|
|
208
|
+
*/
|
|
209
|
+
as(unit: DateUnit): number;
|
|
210
|
+
/**
|
|
211
|
+
* The whole duration expressed in days (fractional)
|
|
212
|
+
*
|
|
213
|
+
* @returns {number} The duration in days
|
|
214
|
+
* @memberof Duration
|
|
215
|
+
*/
|
|
216
|
+
asDays(): number;
|
|
217
|
+
/**
|
|
218
|
+
* The whole duration expressed in hours (fractional)
|
|
219
|
+
*
|
|
220
|
+
* @returns {number} The duration in hours
|
|
221
|
+
* @memberof Duration
|
|
222
|
+
*/
|
|
223
|
+
asHours(): number;
|
|
224
|
+
/**
|
|
225
|
+
* The whole duration expressed in milliseconds
|
|
226
|
+
*
|
|
227
|
+
* @returns {number} The duration in milliseconds
|
|
228
|
+
* @memberof Duration
|
|
229
|
+
*/
|
|
230
|
+
asMilliseconds(): number;
|
|
231
|
+
/**
|
|
232
|
+
* The whole duration expressed in minutes (fractional)
|
|
233
|
+
*
|
|
234
|
+
* @returns {number} The duration in minutes
|
|
235
|
+
* @memberof Duration
|
|
236
|
+
*/
|
|
237
|
+
asMinutes(): number;
|
|
238
|
+
/**
|
|
239
|
+
* The whole duration expressed in months (fractional, 1 month = 30 days)
|
|
240
|
+
*
|
|
241
|
+
* @returns {number} The duration in months
|
|
242
|
+
* @memberof Duration
|
|
243
|
+
*/
|
|
244
|
+
asMonths(): number;
|
|
245
|
+
/**
|
|
246
|
+
* The whole duration expressed in seconds (fractional)
|
|
247
|
+
*
|
|
248
|
+
* @returns {number} The duration in seconds
|
|
249
|
+
* @memberof Duration
|
|
250
|
+
*/
|
|
251
|
+
asSeconds(): number;
|
|
252
|
+
/**
|
|
253
|
+
* The whole duration expressed in weeks (fractional)
|
|
254
|
+
*
|
|
255
|
+
* @returns {number} The duration in weeks
|
|
256
|
+
* @memberof Duration
|
|
257
|
+
*/
|
|
258
|
+
asWeeks(): number;
|
|
259
|
+
/**
|
|
260
|
+
* The whole duration expressed in years (fractional, 1 year = 365 days)
|
|
261
|
+
*
|
|
262
|
+
* @returns {number} The duration in years
|
|
263
|
+
* @memberof Duration
|
|
264
|
+
*/
|
|
265
|
+
asYears(): number;
|
|
266
|
+
/**
|
|
267
|
+
* The days component after extracting whole years and months
|
|
268
|
+
*
|
|
269
|
+
* @returns {number} The days component
|
|
270
|
+
* @memberof Duration
|
|
271
|
+
*/
|
|
272
|
+
days(): number;
|
|
273
|
+
/**
|
|
274
|
+
* Formats the duration with Day.js-style duration tokens.
|
|
275
|
+
*
|
|
276
|
+
* Supported tokens: `Y` `YY` `YYYY` `M` `MM` `D` `DD` `H` `HH` `m` `mm` `s` `ss` `SSS`.
|
|
277
|
+
* Wrap literal text in `[square brackets]`.
|
|
278
|
+
*
|
|
279
|
+
* @param {string} [pattern='HH:mm:ss'] - The token pattern
|
|
280
|
+
* @returns {string} The formatted duration
|
|
281
|
+
* @memberof Duration
|
|
282
|
+
*/
|
|
283
|
+
format(pattern?: string): string;
|
|
284
|
+
/**
|
|
285
|
+
* Returns the duration component for a unit.
|
|
286
|
+
*
|
|
287
|
+
* @param {DateUnit} unit - The component unit
|
|
288
|
+
* @returns {number} The component value
|
|
289
|
+
* @memberof Duration
|
|
290
|
+
*/
|
|
291
|
+
get(unit: DateUnit): number;
|
|
292
|
+
/**
|
|
293
|
+
* The hours component
|
|
294
|
+
*
|
|
295
|
+
* @returns {number} The hours component
|
|
296
|
+
* @memberof Duration
|
|
297
|
+
*/
|
|
298
|
+
hours(): number;
|
|
299
|
+
/**
|
|
300
|
+
* Returns a human-readable, locale-aware string for the duration (e.g. '2 days', 'in 2 days')
|
|
301
|
+
*
|
|
302
|
+
* @param {boolean} [withSuffix=false] - Include a relative suffix (past/future) based on the sign
|
|
303
|
+
* @returns {string} The humanized string
|
|
304
|
+
* @memberof Duration
|
|
305
|
+
*/
|
|
306
|
+
humanize(withSuffix?: boolean): string;
|
|
307
|
+
/**
|
|
308
|
+
* The milliseconds component
|
|
309
|
+
*
|
|
310
|
+
* @returns {number} The milliseconds component
|
|
311
|
+
* @memberof Duration
|
|
312
|
+
*/
|
|
313
|
+
milliseconds(): number;
|
|
314
|
+
/**
|
|
315
|
+
* The minutes component
|
|
316
|
+
*
|
|
317
|
+
* @returns {number} The minutes component
|
|
318
|
+
* @memberof Duration
|
|
319
|
+
*/
|
|
320
|
+
minutes(): number;
|
|
321
|
+
/**
|
|
322
|
+
* The months component after extracting whole years
|
|
323
|
+
*
|
|
324
|
+
* @returns {number} The months component
|
|
325
|
+
* @memberof Duration
|
|
326
|
+
*/
|
|
327
|
+
months(): number;
|
|
328
|
+
/**
|
|
329
|
+
* The seconds component
|
|
330
|
+
*
|
|
331
|
+
* @returns {number} The seconds component
|
|
332
|
+
* @memberof Duration
|
|
333
|
+
*/
|
|
334
|
+
seconds(): number;
|
|
335
|
+
/**
|
|
336
|
+
* Returns a new Duration with the given amount subtracted
|
|
337
|
+
*
|
|
338
|
+
* @param {number} value - The amount to subtract
|
|
339
|
+
* @param {DateUnit} [unit='millisecond'] - The unit of the amount
|
|
340
|
+
* @returns {Duration} The new Duration
|
|
341
|
+
* @memberof Duration
|
|
342
|
+
*/
|
|
343
|
+
subtract(value: number, unit?: DateUnit): Duration;
|
|
344
|
+
/**
|
|
345
|
+
* Returns the ISO 8601 duration representation (e.g. 'P1Y2M3DT4H5M6S')
|
|
346
|
+
*
|
|
347
|
+
* @returns {string} The ISO 8601 duration string
|
|
348
|
+
* @memberof Duration
|
|
349
|
+
*/
|
|
350
|
+
toISOString(): string;
|
|
351
|
+
/**
|
|
352
|
+
* Serializes the duration as its ISO 8601 string (so `JSON.stringify` works)
|
|
353
|
+
*
|
|
354
|
+
* @returns {string} The ISO 8601 duration string
|
|
355
|
+
* @memberof Duration
|
|
356
|
+
*/
|
|
357
|
+
toJSON(): string;
|
|
358
|
+
/**
|
|
359
|
+
* The total duration in milliseconds (enables numeric coercion, e.g. `+duration`)
|
|
360
|
+
*
|
|
361
|
+
* @returns {number} The duration in milliseconds
|
|
362
|
+
* @memberof Duration
|
|
363
|
+
*/
|
|
364
|
+
valueOf(): number;
|
|
365
|
+
/**
|
|
366
|
+
* The years component
|
|
367
|
+
*
|
|
368
|
+
* @returns {number} The years component
|
|
369
|
+
* @memberof Duration
|
|
370
|
+
*/
|
|
371
|
+
years(): number;
|
|
372
|
+
private absComponents;
|
|
373
|
+
/**
|
|
374
|
+
* Decomposes the absolute duration into signed calendar components (years → milliseconds).
|
|
375
|
+
*/
|
|
376
|
+
private components;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Framework-agnostic, fully timezone-aware date utility class.
|
|
381
|
+
*
|
|
382
|
+
* Instances are immutable: every getter/setter-style method returns a brand new
|
|
383
|
+
* `DateTick` rather than mutating the current one, so it is safe to share instances
|
|
384
|
+
* across Angular components, React renders, Vue computed properties, or plain scripts.
|
|
385
|
+
*
|
|
386
|
+
* Every calendar operation — reading components, setting them, `add`/`subtract`,
|
|
387
|
+
* `startOf`/`endOf`, week/quarter math and formatting — is resolved through the configured
|
|
388
|
+
* IANA `timezone`, so a single absolute instant is consistently interpreted in one zone.
|
|
389
|
+
*
|
|
390
|
+
* @class DateTick
|
|
391
|
+
* @author Andreas Nicolaou <anicolaou66@gmail.com>
|
|
392
|
+
*/
|
|
393
|
+
declare class DateTick {
|
|
394
|
+
private readonly _date;
|
|
395
|
+
private readonly _locale;
|
|
396
|
+
private readonly _ordinal?;
|
|
397
|
+
private readonly _timezone;
|
|
398
|
+
private readonly _weekStartsOn;
|
|
399
|
+
/**
|
|
400
|
+
* Creates a new DateTick instance.
|
|
401
|
+
*
|
|
402
|
+
* @param {string} [locale='en'] - The BCP 47 locale used for formatting
|
|
403
|
+
* @param {string} [timezone] - The IANA timezone all calendar operations resolve through (defaults to the runtime's timezone)
|
|
404
|
+
* @param {DateInput} [date] - The wrapped instant or zoned wall-clock parts (defaults to now). Date instances are cloned defensively.
|
|
405
|
+
* @param {number} [weekStartsOn=0] - First day of the week (0 = Sunday … 6 = Saturday), used by `week()` and `startOf`/`endOf('week')`
|
|
406
|
+
* @param {OrdinalFn} [ordinal] - Overrides the English ordinal used by `ordinal()` and the `Do`/`wo`/`Wo` tokens
|
|
407
|
+
* @memberof DateTick
|
|
408
|
+
*/
|
|
409
|
+
constructor(locale?: string, timezone?: string, date?: DateInput, weekStartsOn?: number, ordinal?: OrdinalFn);
|
|
410
|
+
/**
|
|
411
|
+
* Creates a {@link Duration} representing a length of time.
|
|
412
|
+
*
|
|
413
|
+
* @param {number | string | DurationInput} value - A millisecond amount, an amount paired with `unit`,
|
|
414
|
+
* an ISO 8601 duration string (e.g. 'P1Y2M10DT2H30M'), or a components object
|
|
415
|
+
* @param {DateUnit} [unit] - The unit when `value` is a number (defaults to milliseconds)
|
|
416
|
+
* @param {string} [locale='en'] - The locale used by `humanize()`
|
|
417
|
+
* @returns {Duration} The duration
|
|
418
|
+
* @example DateTick.duration(2, 'hour').humanize() // '2 hours'
|
|
419
|
+
* @memberof DateTick
|
|
420
|
+
*/
|
|
421
|
+
static duration(value: number | string | DurationInput, unit?: DateUnit, locale?: string): Duration;
|
|
422
|
+
/**
|
|
423
|
+
* Returns the runtime's best-guess IANA timezone.
|
|
424
|
+
*
|
|
425
|
+
* @returns {string} The guessed IANA timezone
|
|
426
|
+
* @memberof DateTick
|
|
427
|
+
*/
|
|
428
|
+
static guessTimezone(): string;
|
|
429
|
+
/**
|
|
430
|
+
* Checks whether a value is a DateTick instance.
|
|
431
|
+
*
|
|
432
|
+
* @param {unknown} value - The value to check
|
|
433
|
+
* @returns {boolean} True if the value is a DateTick
|
|
434
|
+
* @memberof DateTick
|
|
435
|
+
*/
|
|
436
|
+
static isDateTick(value: unknown): value is DateTick;
|
|
437
|
+
/**
|
|
438
|
+
* Checks if a date value is valid
|
|
439
|
+
*
|
|
440
|
+
* @param {DateInput} date - The date to validate
|
|
441
|
+
* @returns {boolean} True if valid, false otherwise
|
|
442
|
+
* @memberof DateTick
|
|
443
|
+
*/
|
|
444
|
+
static isValid(date: DateInput): boolean;
|
|
445
|
+
/**
|
|
446
|
+
* Returns the maximum (latest) date from a list
|
|
447
|
+
*
|
|
448
|
+
* @param {...DateInput[]} dates - Dates to compare
|
|
449
|
+
* @returns {Date} The latest date
|
|
450
|
+
* @memberof DateTick
|
|
451
|
+
*/
|
|
452
|
+
static max(...dates: DateInput[]): Date;
|
|
453
|
+
/**
|
|
454
|
+
* Returns the minimum (earliest) date from a list
|
|
455
|
+
*
|
|
456
|
+
* @param {...DateInput[]} dates - Dates to compare
|
|
457
|
+
* @returns {Date} The earliest date
|
|
458
|
+
* @memberof DateTick
|
|
459
|
+
*/
|
|
460
|
+
static min(...dates: DateInput[]): Date;
|
|
461
|
+
/**
|
|
462
|
+
* Parses a string into a DateTick using an explicit token pattern, interpreting the wall-clock
|
|
463
|
+
* values in the given timezone. Supported tokens mirror {@link DateTick.formatPattern}; anything
|
|
464
|
+
* else (and text wrapped in `[square brackets]`) is treated as a literal.
|
|
465
|
+
*
|
|
466
|
+
* @param {string} input - The string to parse (e.g. '25/06/2026 22:23')
|
|
467
|
+
* @param {string} pattern - The token pattern (e.g. 'DD/MM/YYYY HH:mm')
|
|
468
|
+
* @param {string} [locale='en'] - The BCP 47 locale (also used to resolve month names)
|
|
469
|
+
* @param {string} [timezone] - The IANA timezone the wall-clock values belong to
|
|
470
|
+
* @returns {DateTick} The parsed DateTick
|
|
471
|
+
* @throws {Error} If the input does not match the pattern
|
|
472
|
+
* @memberof DateTick
|
|
473
|
+
*/
|
|
474
|
+
static parse(input: string, pattern: string, locale?: string, timezone?: string): DateTick;
|
|
475
|
+
private static inputParts;
|
|
476
|
+
private static resolveInput;
|
|
477
|
+
/**
|
|
478
|
+
* Adds a specified amount of time to the wrapped date (chainable, immutable).
|
|
479
|
+
*
|
|
480
|
+
* Calendar units (`date`/`day`, `week`, `month`, `quarter`, `year`) preserve the wall-clock
|
|
481
|
+
* time in the configured timezone (so they survive DST). Fixed-duration units
|
|
482
|
+
* (`millisecond`/`second`/`minute`/`hour`) add absolute time. Month/year additions clamp the day
|
|
483
|
+
* to the last day of the resulting month instead of overflowing (Jan 31 + 1 month -> Feb 28/29).
|
|
484
|
+
*
|
|
485
|
+
* @param {number} amount - The amount to add (negative values subtract)
|
|
486
|
+
* @param {DateUnit} unit - The unit to add (e.g. 'day', 'month')
|
|
487
|
+
* @returns {DateTick} A new DateTick with the result
|
|
488
|
+
* @memberof DateTick
|
|
489
|
+
*/
|
|
490
|
+
add(amount: number, unit: DateUnit): DateTick;
|
|
491
|
+
/**
|
|
492
|
+
* Formats the date as a calendar-style relative label such as "Today at 7:23 PM".
|
|
493
|
+
*
|
|
494
|
+
* @param {DateInput} [reference] - The date to compare against (defaults to now)
|
|
495
|
+
* @param {CalendarDisplayFormats} [formats] - Token patterns or callbacks for each calendar bucket
|
|
496
|
+
* @returns {string} The calendar-style label
|
|
497
|
+
* @memberof DateTick
|
|
498
|
+
*/
|
|
499
|
+
calendar(reference?: DateInput, formats?: CalendarDisplayFormats): string;
|
|
500
|
+
/**
|
|
501
|
+
* Returns localized month-grid data for rendering a calendar UI.
|
|
502
|
+
*
|
|
503
|
+
* The grid is padded with adjacent-month dates so every week has seven cells,
|
|
504
|
+
* and the weekday order follows the configured `weekStartsOn`.
|
|
505
|
+
*
|
|
506
|
+
* @returns {CalendarMonth} Calendar data for the wrapped date's month
|
|
507
|
+
* @memberof DateTick
|
|
508
|
+
*/
|
|
509
|
+
calendarMonth(options?: CalendarMonthOptions): CalendarMonth;
|
|
510
|
+
/**
|
|
511
|
+
* Returns a new DateTick with the exact same instant, locale and timezone
|
|
512
|
+
*
|
|
513
|
+
* @returns {DateTick} The cloned instance
|
|
514
|
+
* @memberof DateTick
|
|
515
|
+
*/
|
|
516
|
+
clone(): DateTick;
|
|
517
|
+
/**
|
|
518
|
+
* Gets or sets the day of the month (in the configured timezone)
|
|
519
|
+
*
|
|
520
|
+
* @param {number} [value] - The day of the month to set
|
|
521
|
+
* @returns {number | DateTick} The day of the month, or a new DateTick when setting
|
|
522
|
+
* @memberof DateTick
|
|
523
|
+
*/
|
|
524
|
+
date(): number;
|
|
525
|
+
date(value: number): DateTick;
|
|
526
|
+
/** Day.js-style plural alias of {@link DateTick.date} (day of the month). */
|
|
527
|
+
dates(): number;
|
|
528
|
+
dates(value: number): DateTick;
|
|
529
|
+
/**
|
|
530
|
+
* Gets or sets the day of the week (0 = Sunday … 6 = Saturday, in the configured timezone)
|
|
531
|
+
*
|
|
532
|
+
* @param {number} [value] - The day of the week to set
|
|
533
|
+
* @returns {number | DateTick} The day of the week, or a new DateTick when setting
|
|
534
|
+
* @memberof DateTick
|
|
535
|
+
*/
|
|
536
|
+
day(): number;
|
|
537
|
+
day(value: number): DateTick;
|
|
538
|
+
/**
|
|
539
|
+
* Gets or sets the day of the year (1-based, in the configured timezone).
|
|
540
|
+
*
|
|
541
|
+
* Setting beyond the number of days in the year rolls over into the following year(s),
|
|
542
|
+
* the same way a native `Date` rolls over an out-of-range day-of-month.
|
|
543
|
+
*
|
|
544
|
+
* @param {number} [value] - The day of the year to set
|
|
545
|
+
* @returns {number | DateTick} The day of the year, or a new DateTick when setting
|
|
546
|
+
* @memberof DateTick
|
|
547
|
+
*/
|
|
548
|
+
dayOfYear(): number;
|
|
549
|
+
dayOfYear(value: number): DateTick;
|
|
550
|
+
/** Day.js-style plural alias of {@link DateTick.day} (day of the week). */
|
|
551
|
+
days(): number;
|
|
552
|
+
days(value: number): DateTick;
|
|
553
|
+
/**
|
|
554
|
+
* Gets the number of days in the wrapped date's month (in the configured timezone)
|
|
555
|
+
*
|
|
556
|
+
* @returns {number} The number of days in the month
|
|
557
|
+
* @memberof DateTick
|
|
558
|
+
*/
|
|
559
|
+
daysInMonth(): number;
|
|
560
|
+
/**
|
|
561
|
+
* Gets the difference between the wrapped date and another date.
|
|
562
|
+
*
|
|
563
|
+
* @param {DateInput} date - The date to compare against
|
|
564
|
+
* @param {DateUnit} [unit='millisecond'] - The unit of measurement
|
|
565
|
+
* @param {boolean} [precise=false] - When true, returns a floating-point value instead of truncating.
|
|
566
|
+
* For `month`/`quarter`/`year` the fractional part reflects progress through the current calendar unit.
|
|
567
|
+
* @returns {number} The difference (positive when the wrapped date is later)
|
|
568
|
+
* @memberof DateTick
|
|
569
|
+
*/
|
|
570
|
+
diff(date: DateInput, unit?: DateUnit, precise?: boolean): number;
|
|
571
|
+
/**
|
|
572
|
+
* Calendar-boundary difference in the configured timezone.
|
|
573
|
+
*
|
|
574
|
+
* Unlike {@link DateTick.diff}, this counts calendar units rather than elapsed duration.
|
|
575
|
+
* For example, Friday 23:00 to Saturday 01:00 is one calendar day apart even though
|
|
576
|
+
* only two hours elapsed.
|
|
577
|
+
*
|
|
578
|
+
* @param {DateInput} date - The date to compare against
|
|
579
|
+
* @param {CalendarDiffUnit} [unit='day'] - Calendar unit to compare
|
|
580
|
+
* @returns {number} The calendar difference, positive when this instance is later
|
|
581
|
+
* @memberof DateTick
|
|
582
|
+
*/
|
|
583
|
+
diffCalendar(date: DateInput, unit?: CalendarDiffUnit): number;
|
|
584
|
+
/**
|
|
585
|
+
* Returns a new DateTick set to the end of the given unit (one millisecond before the next unit starts)
|
|
586
|
+
*
|
|
587
|
+
* @param {DateUnit} unit - The unit to snap to (e.g. 'month', 'day')
|
|
588
|
+
* @returns {DateTick} A new DateTick at the end of the unit
|
|
589
|
+
* @memberof DateTick
|
|
590
|
+
*/
|
|
591
|
+
endOf(unit: DateUnit): DateTick;
|
|
592
|
+
/**
|
|
593
|
+
* Formats a date using Intl.DateTimeFormat or a preset (in the configured timezone)
|
|
594
|
+
*
|
|
595
|
+
* @param {Intl.DateTimeFormatOptions | DateFormatPreset} [format] - Format options or preset
|
|
596
|
+
* @returns {string} The formatted date string
|
|
597
|
+
* @memberof DateTick
|
|
598
|
+
*/
|
|
599
|
+
format(format?: Intl.DateTimeFormatOptions | DateFormatPreset): string;
|
|
600
|
+
/**
|
|
601
|
+
* Formats the date using a token pattern, resolved in the configured timezone.
|
|
602
|
+
*
|
|
603
|
+
* Core tokens: `YYYY` `YY` `MMMM` `MMM` `MM` `M` `DD` `D` `dddd` `ddd` `dd` `d` `HH` `H` `hh` `h`
|
|
604
|
+
* `mm` `m` `ss` `s` `SSS` `A` `a` `Z` `ZZ`. Advanced: `Do` `Q` `k` `kk` `X` `x` `w` `ww` `wo` `W` `WW` `Wo`.
|
|
605
|
+
* Localized (resolved to the configured locale's field order and separators): `L` `LL` `LLL` `LLLL`
|
|
606
|
+
* `l` `ll` `lll` `llll` `LT` `LTS`. Wrap literal text in `[square brackets]`.
|
|
607
|
+
*
|
|
608
|
+
* @param {string} pattern - The token pattern (e.g. 'DD/MM/YYYY HH:mm')
|
|
609
|
+
* @returns {string} The formatted string
|
|
610
|
+
* @example date.formatPattern('DD/MM/YYYY') // '25/06/2026'
|
|
611
|
+
* @memberof DateTick
|
|
612
|
+
*/
|
|
613
|
+
formatPattern(pattern: string): string;
|
|
614
|
+
/**
|
|
615
|
+
* Formats the date relative to another date, Day.js-style.
|
|
616
|
+
*
|
|
617
|
+
* @param {DateInput} date - The date to compare from
|
|
618
|
+
* @param {boolean} [withoutSuffix=false] - When true, omit "ago" / "in"
|
|
619
|
+
* @returns {string} The relative-time label
|
|
620
|
+
* @memberof DateTick
|
|
621
|
+
*/
|
|
622
|
+
from(date: DateInput, withoutSuffix?: boolean): string;
|
|
623
|
+
/**
|
|
624
|
+
* Formats the date relative to now, Day.js-style.
|
|
625
|
+
*
|
|
626
|
+
* @param {boolean} [withoutSuffix=false] - When true, omit "ago" / "in"
|
|
627
|
+
* @returns {string} The relative-time label
|
|
628
|
+
* @memberof DateTick
|
|
629
|
+
*/
|
|
630
|
+
fromNow(withoutSuffix?: boolean): string;
|
|
631
|
+
/**
|
|
632
|
+
* Gets a specific unit (or derived value) from the wrapped date
|
|
633
|
+
*
|
|
634
|
+
* @param {DateGettableUnit} unit - The unit to get (e.g. 'year', 'isoWeek')
|
|
635
|
+
* @returns {number} The value of the unit
|
|
636
|
+
* @memberof DateTick
|
|
637
|
+
*/
|
|
638
|
+
get(unit: DateGettableUnit): number;
|
|
639
|
+
/**
|
|
640
|
+
* Gets or sets the hour (in the configured timezone)
|
|
641
|
+
*
|
|
642
|
+
* @param {number} [value] - The hour to set
|
|
643
|
+
* @returns {number | DateTick} The hour, or a new DateTick when setting
|
|
644
|
+
* @memberof DateTick
|
|
645
|
+
*/
|
|
646
|
+
hour(): number;
|
|
647
|
+
hour(value: number): DateTick;
|
|
648
|
+
/** Day.js-style plural alias of {@link DateTick.hour}. */
|
|
649
|
+
hours(): number;
|
|
650
|
+
hours(value: number): DateTick;
|
|
651
|
+
/**
|
|
652
|
+
* Checks if the wrapped date is strictly after another date
|
|
653
|
+
*
|
|
654
|
+
* @param {DateInput} date - The date to compare against
|
|
655
|
+
* @returns {boolean} True if the wrapped date is later
|
|
656
|
+
* @memberof DateTick
|
|
657
|
+
*/
|
|
658
|
+
isAfter(date: DateInput): boolean;
|
|
659
|
+
/**
|
|
660
|
+
* Checks if the wrapped date is strictly before another date
|
|
661
|
+
*
|
|
662
|
+
* @param {DateInput} date - The date to compare against
|
|
663
|
+
* @returns {boolean} True if the wrapped date is earlier
|
|
664
|
+
* @memberof DateTick
|
|
665
|
+
*/
|
|
666
|
+
isBefore(date: DateInput): boolean;
|
|
667
|
+
/**
|
|
668
|
+
* Checks if the wrapped date falls between two dates.
|
|
669
|
+
*
|
|
670
|
+
* @param {DateInput} start - The lower bound
|
|
671
|
+
* @param {DateInput} end - The upper bound
|
|
672
|
+
* @param {boolean | Inclusivity} [inclusivity=false] - `false`/`'()'` excludes both bounds,
|
|
673
|
+
* `true`/`'[]'` includes both, or use `'(]'`/`'[)'` to control each side independently
|
|
674
|
+
* @returns {boolean} True if the wrapped date is between start and end
|
|
675
|
+
* @memberof DateTick
|
|
676
|
+
*/
|
|
677
|
+
isBetween(start: DateInput, end: DateInput, inclusivity?: boolean | Inclusivity): boolean;
|
|
678
|
+
/**
|
|
679
|
+
* Checks if the wrapped date's year is a leap year (in the configured timezone)
|
|
680
|
+
*
|
|
681
|
+
* @returns {boolean} True if the year is a leap year
|
|
682
|
+
* @memberof DateTick
|
|
683
|
+
*/
|
|
684
|
+
isLeapYear(): boolean;
|
|
685
|
+
/**
|
|
686
|
+
* Checks if the wrapped date is the same as another date, optionally truncated to a unit
|
|
687
|
+
*
|
|
688
|
+
* @param {DateInput} date - The date to compare against
|
|
689
|
+
* @param {DateUnit} [unit] - When provided, compares after snapping both dates to the start of this unit
|
|
690
|
+
* @returns {boolean} True if the dates are the same
|
|
691
|
+
* @memberof DateTick
|
|
692
|
+
*/
|
|
693
|
+
isSame(date: DateInput, unit?: DateUnit): boolean;
|
|
694
|
+
/**
|
|
695
|
+
* Checks if the wrapped date is the same as or after another date, optionally truncated to a unit
|
|
696
|
+
*
|
|
697
|
+
* @param {DateInput} date - The date to compare against
|
|
698
|
+
* @param {DateUnit} [unit] - When provided, compares after snapping both dates to the start of this unit
|
|
699
|
+
* @returns {boolean} True if the wrapped date is the same as or later than the other
|
|
700
|
+
* @memberof DateTick
|
|
701
|
+
*/
|
|
702
|
+
isSameOrAfter(date: DateInput, unit?: DateUnit): boolean;
|
|
703
|
+
/**
|
|
704
|
+
* Checks if the wrapped date is the same as or before another date, optionally truncated to a unit
|
|
705
|
+
*
|
|
706
|
+
* @param {DateInput} date - The date to compare against
|
|
707
|
+
* @param {DateUnit} [unit] - When provided, compares after snapping both dates to the start of this unit
|
|
708
|
+
* @returns {boolean} True if the wrapped date is the same as or earlier than the other
|
|
709
|
+
* @memberof DateTick
|
|
710
|
+
*/
|
|
711
|
+
isSameOrBefore(date: DateInput, unit?: DateUnit): boolean;
|
|
712
|
+
/**
|
|
713
|
+
* Checks if the wrapped date is today in the configured timezone.
|
|
714
|
+
*
|
|
715
|
+
* @returns {boolean} True if the date is today
|
|
716
|
+
* @memberof DateTick
|
|
717
|
+
*/
|
|
718
|
+
isToday(): boolean;
|
|
719
|
+
/**
|
|
720
|
+
* Checks if the wrapped date is tomorrow in the configured timezone.
|
|
721
|
+
*
|
|
722
|
+
* @returns {boolean} True if the date is tomorrow
|
|
723
|
+
* @memberof DateTick
|
|
724
|
+
*/
|
|
725
|
+
isTomorrow(): boolean;
|
|
726
|
+
/**
|
|
727
|
+
* Checks whether the wrapped date itself is a valid date
|
|
728
|
+
*
|
|
729
|
+
* @returns {boolean} True if valid, false otherwise
|
|
730
|
+
* @memberof DateTick
|
|
731
|
+
*/
|
|
732
|
+
isValid(): boolean;
|
|
733
|
+
/**
|
|
734
|
+
* Checks if the wrapped date is yesterday in the configured timezone.
|
|
735
|
+
*
|
|
736
|
+
* @returns {boolean} True if the date is yesterday
|
|
737
|
+
* @memberof DateTick
|
|
738
|
+
*/
|
|
739
|
+
isYesterday(): boolean;
|
|
740
|
+
/**
|
|
741
|
+
* Gets the ISO day of the week (1-7, Monday-Sunday, in the configured timezone)
|
|
742
|
+
*
|
|
743
|
+
* @returns {number} The ISO day
|
|
744
|
+
* @memberof DateTick
|
|
745
|
+
*/
|
|
746
|
+
isoDay(): number;
|
|
747
|
+
/**
|
|
748
|
+
* Gets the ISO week number (in the configured timezone)
|
|
749
|
+
*
|
|
750
|
+
* @returns {number} The ISO week number
|
|
751
|
+
* @memberof DateTick
|
|
752
|
+
*/
|
|
753
|
+
isoWeek(): number;
|
|
754
|
+
/**
|
|
755
|
+
* Gets the ISO week year (in the configured timezone)
|
|
756
|
+
*
|
|
757
|
+
* @returns {number} The ISO week year
|
|
758
|
+
* @memberof DateTick
|
|
759
|
+
*/
|
|
760
|
+
isoWeekYear(): number;
|
|
761
|
+
/**
|
|
762
|
+
* Gets the number of ISO weeks in the year (in the configured timezone)
|
|
763
|
+
*
|
|
764
|
+
* @returns {number} The number of ISO weeks
|
|
765
|
+
* @memberof DateTick
|
|
766
|
+
*/
|
|
767
|
+
isoWeeksInYear(): number;
|
|
768
|
+
/**
|
|
769
|
+
* Returns a new DateTick in the runtime's local timezone, keeping the same instant.
|
|
770
|
+
*
|
|
771
|
+
* @returns {DateTick} The local-timezone instance
|
|
772
|
+
* @memberof DateTick
|
|
773
|
+
*/
|
|
774
|
+
local(): DateTick;
|
|
775
|
+
/**
|
|
776
|
+
* Gets the configured locale
|
|
777
|
+
*
|
|
778
|
+
* @returns {string} The BCP 47 locale
|
|
779
|
+
* @memberof DateTick
|
|
780
|
+
*/
|
|
781
|
+
locale(): string;
|
|
782
|
+
/**
|
|
783
|
+
* Returns locale metadata (month/weekday names, first day of week, meridiems, ordinal), resolved
|
|
784
|
+
* through `Intl` — the Day.js `localeData()` equivalent.
|
|
785
|
+
*
|
|
786
|
+
* @returns {LocaleData} The locale metadata
|
|
787
|
+
* @example datetick('2026-06-25', { locale: 'fr' }).localeData().months()[0] // 'janvier'
|
|
788
|
+
* @memberof DateTick
|
|
789
|
+
*/
|
|
790
|
+
localeData(): LocaleData;
|
|
791
|
+
/**
|
|
792
|
+
* Gets or sets the milliseconds
|
|
793
|
+
*
|
|
794
|
+
* @param {number} [value] - The milliseconds to set
|
|
795
|
+
* @returns {number | DateTick} The milliseconds, or a new DateTick when setting
|
|
796
|
+
* @memberof DateTick
|
|
797
|
+
*/
|
|
798
|
+
millisecond(): number;
|
|
799
|
+
millisecond(value: number): DateTick;
|
|
800
|
+
/** Day.js-style plural alias of {@link DateTick.millisecond}. */
|
|
801
|
+
milliseconds(): number;
|
|
802
|
+
milliseconds(value: number): DateTick;
|
|
803
|
+
/**
|
|
804
|
+
* Gets or sets the minutes (in the configured timezone)
|
|
805
|
+
*
|
|
806
|
+
* @param {number} [value] - The minutes to set
|
|
807
|
+
* @returns {number | DateTick} The minutes, or a new DateTick when setting
|
|
808
|
+
* @memberof DateTick
|
|
809
|
+
*/
|
|
810
|
+
minute(): number;
|
|
811
|
+
minute(value: number): DateTick;
|
|
812
|
+
/** Day.js-style plural alias of {@link DateTick.minute}. */
|
|
813
|
+
minutes(): number;
|
|
814
|
+
minutes(value: number): DateTick;
|
|
815
|
+
/**
|
|
816
|
+
* Gets or sets the month (0-11, in the configured timezone)
|
|
817
|
+
*
|
|
818
|
+
* @param {number} [value] - The month to set
|
|
819
|
+
* @returns {number | DateTick} The month, or a new DateTick when setting
|
|
820
|
+
* @memberof DateTick
|
|
821
|
+
*/
|
|
822
|
+
month(): number;
|
|
823
|
+
month(value: number): DateTick;
|
|
824
|
+
/** Day.js-style plural alias of {@link DateTick.month}. */
|
|
825
|
+
months(): number;
|
|
826
|
+
months(value: number): DateTick;
|
|
827
|
+
/**
|
|
828
|
+
* Gets the day of the month with its ordinal suffix (e.g. '1st', '22nd', '31st'). English by default,
|
|
829
|
+
* or the factory's `ordinal` override when one is configured.
|
|
830
|
+
*
|
|
831
|
+
* @returns {string} The ordinal day-of-month
|
|
832
|
+
* @memberof DateTick
|
|
833
|
+
*/
|
|
834
|
+
ordinal(): string;
|
|
835
|
+
/**
|
|
836
|
+
* Gets or sets the quarter of the year (1-4, in the configured timezone).
|
|
837
|
+
*
|
|
838
|
+
* Setting preserves the current month's offset within its quarter (e.g. the 2nd month of
|
|
839
|
+
* the quarter stays the 2nd month) while moving to the target quarter.
|
|
840
|
+
*
|
|
841
|
+
* @param {number} [value] - The quarter (1-4) to set
|
|
842
|
+
* @returns {number | DateTick} The quarter, or a new DateTick when setting
|
|
843
|
+
* @memberof DateTick
|
|
844
|
+
*/
|
|
845
|
+
quarter(): number;
|
|
846
|
+
quarter(value: number): DateTick;
|
|
847
|
+
/**
|
|
848
|
+
* Gets or sets the seconds (in the configured timezone)
|
|
849
|
+
*
|
|
850
|
+
* @param {number} [value] - The seconds to set
|
|
851
|
+
* @returns {number | DateTick} The seconds, or a new DateTick when setting
|
|
852
|
+
* @memberof DateTick
|
|
853
|
+
*/
|
|
854
|
+
second(): number;
|
|
855
|
+
second(value: number): DateTick;
|
|
856
|
+
/** Day.js-style plural alias of {@link DateTick.second}. */
|
|
857
|
+
seconds(): number;
|
|
858
|
+
seconds(value: number): DateTick;
|
|
859
|
+
/**
|
|
860
|
+
* Sets a specific unit on the wrapped date
|
|
861
|
+
*
|
|
862
|
+
* @param {DateUnit} unit - The unit to set (e.g. 'year', 'month')
|
|
863
|
+
* @param {number} value - The value to set
|
|
864
|
+
* @returns {DateTick} A new DateTick with the result
|
|
865
|
+
* @memberof DateTick
|
|
866
|
+
*/
|
|
867
|
+
set(unit: DateUnit, value: number): DateTick;
|
|
868
|
+
/**
|
|
869
|
+
* Returns a new DateTick set to the start of the given unit (in the configured timezone)
|
|
870
|
+
*
|
|
871
|
+
* @param {DateUnit} unit - The unit to snap to (e.g. 'month', 'day')
|
|
872
|
+
* @returns {DateTick} A new DateTick at the start of the unit
|
|
873
|
+
* @memberof DateTick
|
|
874
|
+
*/
|
|
875
|
+
startOf(unit: DateUnit): DateTick;
|
|
876
|
+
/**
|
|
877
|
+
* Subtracts a specified amount of time from the wrapped date (chainable, immutable)
|
|
878
|
+
*
|
|
879
|
+
* @param {number} amount - The amount to subtract
|
|
880
|
+
* @param {DateUnit} unit - The unit to subtract (e.g. 'day', 'month')
|
|
881
|
+
* @returns {DateTick} A new DateTick with the result
|
|
882
|
+
* @memberof DateTick
|
|
883
|
+
*/
|
|
884
|
+
subtract(amount: number, unit: DateUnit): DateTick;
|
|
885
|
+
/**
|
|
886
|
+
* Returns a human-readable relative time string (e.g. '3 minutes ago')
|
|
887
|
+
*
|
|
888
|
+
* @param {Intl.RelativeTimeFormatOptions} [options] - Intl options
|
|
889
|
+
* @param {RelativeTimeThresholds} [thresholds] - Override the unit step-up cutoffs
|
|
890
|
+
* @returns {string} The relative time string
|
|
891
|
+
* @memberof DateTick
|
|
892
|
+
*/
|
|
893
|
+
timeAgo(options?: Intl.RelativeTimeFormatOptions, thresholds?: RelativeTimeThresholds): string;
|
|
894
|
+
/**
|
|
895
|
+
* Returns a dependency-free live relative-time stream.
|
|
896
|
+
*
|
|
897
|
+
* Subscribers receive the current `timeAgo()` label immediately, then again whenever it is
|
|
898
|
+
* expected to change. The refresh rate adapts from every second to every hour as the target
|
|
899
|
+
* time moves farther away.
|
|
900
|
+
*
|
|
901
|
+
* @param {Intl.RelativeTimeFormatOptions} [options] - Intl options
|
|
902
|
+
* @param {RelativeTimeThresholds} [thresholds] - Override the unit step-up cutoffs
|
|
903
|
+
* @returns {TimeAgoLive} A live relative-time subscription handle
|
|
904
|
+
* @memberof DateTick
|
|
905
|
+
*/
|
|
906
|
+
timeAgoLive(options?: Intl.RelativeTimeFormatOptions, thresholds?: RelativeTimeThresholds): TimeAgoLive;
|
|
907
|
+
/**
|
|
908
|
+
* Subscribes to live relative-time labels and returns an unsubscribe function.
|
|
909
|
+
*
|
|
910
|
+
* @param {TimeAgoListener} listener - Receives each formatted relative-time label
|
|
911
|
+
* @param {Intl.RelativeTimeFormatOptions} [options] - Intl options
|
|
912
|
+
* @param {RelativeTimeThresholds} [thresholds] - Override the unit step-up cutoffs
|
|
913
|
+
* @returns {() => void} Function that stops the live updates
|
|
914
|
+
* @memberof DateTick
|
|
915
|
+
*/
|
|
916
|
+
timeAgoSubscribe(listener: TimeAgoListener, options?: Intl.RelativeTimeFormatOptions, thresholds?: RelativeTimeThresholds): () => void;
|
|
917
|
+
/**
|
|
918
|
+
* Gets the configured IANA timezone
|
|
919
|
+
*
|
|
920
|
+
* @returns {string} The timezone
|
|
921
|
+
* @memberof DateTick
|
|
922
|
+
*/
|
|
923
|
+
timezone(): string;
|
|
924
|
+
/**
|
|
925
|
+
* Formats another date relative to this one, Day.js-style.
|
|
926
|
+
*
|
|
927
|
+
* @param {DateInput} date - The target date to compare to
|
|
928
|
+
* @param {boolean} [withoutSuffix=false] - When true, omit "ago" / "in"
|
|
929
|
+
* @returns {string} The relative-time label
|
|
930
|
+
* @memberof DateTick
|
|
931
|
+
*/
|
|
932
|
+
to(date: DateInput, withoutSuffix?: boolean): string;
|
|
933
|
+
/**
|
|
934
|
+
* Converts the wrapped date to an array of zoned calendar parts.
|
|
935
|
+
*
|
|
936
|
+
* @returns {DateArray} [year, month, date, hour, minute, second, millisecond]
|
|
937
|
+
* @memberof DateTick
|
|
938
|
+
*/
|
|
939
|
+
toArray(): Required<DateArray>;
|
|
940
|
+
/**
|
|
941
|
+
* Converts the wrapped date to a plain Date object (a fresh clone of the absolute instant)
|
|
942
|
+
*
|
|
943
|
+
* @returns {Date} The Date object
|
|
944
|
+
* @memberof DateTick
|
|
945
|
+
*/
|
|
946
|
+
toDate(): Date;
|
|
947
|
+
/**
|
|
948
|
+
* Converts the wrapped date to an ISO 8601 string (UTC)
|
|
949
|
+
*
|
|
950
|
+
* @returns {string} The ISO 8601 string
|
|
951
|
+
* @memberof DateTick
|
|
952
|
+
*/
|
|
953
|
+
toISOString(): string;
|
|
954
|
+
/**
|
|
955
|
+
* Enables `JSON.stringify` to serialize a DateTick as an ISO 8601 string
|
|
956
|
+
*
|
|
957
|
+
* @returns {string} The ISO 8601 string
|
|
958
|
+
* @memberof DateTick
|
|
959
|
+
*/
|
|
960
|
+
toJSON(): string;
|
|
961
|
+
/**
|
|
962
|
+
* Formats now relative to this date, Day.js-style.
|
|
963
|
+
*
|
|
964
|
+
* @param {boolean} [withoutSuffix=false] - When true, omit "ago" / "in"
|
|
965
|
+
* @returns {string} The relative-time label
|
|
966
|
+
* @memberof DateTick
|
|
967
|
+
*/
|
|
968
|
+
toNow(withoutSuffix?: boolean): string;
|
|
969
|
+
/**
|
|
970
|
+
* Converts the wrapped date to an object of zoned calendar parts.
|
|
971
|
+
*
|
|
972
|
+
* @returns {DatePartsObject} Zoned calendar parts
|
|
973
|
+
* @memberof DateTick
|
|
974
|
+
*/
|
|
975
|
+
toObject(): DatePartsObject;
|
|
976
|
+
/**
|
|
977
|
+
* Converts the wrapped date to its default string representation
|
|
978
|
+
*
|
|
979
|
+
* @returns {string} The string representation
|
|
980
|
+
* @memberof DateTick
|
|
981
|
+
*/
|
|
982
|
+
toString(): string;
|
|
983
|
+
/**
|
|
984
|
+
* Gets the Unix timestamp (seconds since epoch)
|
|
985
|
+
*
|
|
986
|
+
* @returns {number} The Unix timestamp in seconds
|
|
987
|
+
* @memberof DateTick
|
|
988
|
+
*/
|
|
989
|
+
unix(): number;
|
|
990
|
+
/**
|
|
991
|
+
* Returns a new DateTick in UTC, keeping the same instant.
|
|
992
|
+
*
|
|
993
|
+
* @returns {DateTick} The UTC instance
|
|
994
|
+
* @memberof DateTick
|
|
995
|
+
*/
|
|
996
|
+
utc(): DateTick;
|
|
997
|
+
/**
|
|
998
|
+
* Gets the configured timezone's UTC offset for this instant, in minutes.
|
|
999
|
+
*
|
|
1000
|
+
* @returns {number} Offset minutes, positive east of UTC
|
|
1001
|
+
* @memberof DateTick
|
|
1002
|
+
*/
|
|
1003
|
+
utcOffset(): number;
|
|
1004
|
+
/**
|
|
1005
|
+
* Gets the timestamp in milliseconds since epoch. Enables direct numeric comparisons (e.g. `+datetick`)
|
|
1006
|
+
*
|
|
1007
|
+
* @returns {number} The timestamp in milliseconds
|
|
1008
|
+
* @memberof DateTick
|
|
1009
|
+
*/
|
|
1010
|
+
valueOf(): number;
|
|
1011
|
+
/**
|
|
1012
|
+
* Gets the week number of the year (in the configured timezone)
|
|
1013
|
+
*
|
|
1014
|
+
* @returns {number} The week number
|
|
1015
|
+
* @memberof DateTick
|
|
1016
|
+
*/
|
|
1017
|
+
week(): number;
|
|
1018
|
+
/**
|
|
1019
|
+
* Gets the configured first day of the week (0 = Sunday … 6 = Saturday)
|
|
1020
|
+
*
|
|
1021
|
+
* @returns {number} The first day of the week
|
|
1022
|
+
* @memberof DateTick
|
|
1023
|
+
*/
|
|
1024
|
+
weekStart(): number;
|
|
1025
|
+
/**
|
|
1026
|
+
* Gets the week year, for ISO week calculations (in the configured timezone)
|
|
1027
|
+
*
|
|
1028
|
+
* @returns {number} The week year
|
|
1029
|
+
* @memberof DateTick
|
|
1030
|
+
*/
|
|
1031
|
+
weekYear(): number;
|
|
1032
|
+
/**
|
|
1033
|
+
* Gets or sets the day of the week relative to the configured first day of the week
|
|
1034
|
+
* (0 = first day of the week … 6 = last day), in the configured timezone.
|
|
1035
|
+
*
|
|
1036
|
+
* Unlike {@link DateTick.day}, which is always Sunday-based, this respects `weekStartsOn`.
|
|
1037
|
+
*
|
|
1038
|
+
* @param {number} [value] - The relative day of the week to set
|
|
1039
|
+
* @returns {number | DateTick} The relative day of the week, or a new DateTick when setting
|
|
1040
|
+
* @memberof DateTick
|
|
1041
|
+
*/
|
|
1042
|
+
weekday(): number;
|
|
1043
|
+
weekday(value: number): DateTick;
|
|
1044
|
+
/** Day.js-style plural getter alias of {@link DateTick.week} (weeks have no setter). */
|
|
1045
|
+
weeks(): number;
|
|
1046
|
+
/**
|
|
1047
|
+
* Gets the number of weeks in the year (in the configured timezone)
|
|
1048
|
+
*
|
|
1049
|
+
* @returns {number} The number of weeks
|
|
1050
|
+
* @memberof DateTick
|
|
1051
|
+
*/
|
|
1052
|
+
weeksInYear(): number;
|
|
1053
|
+
/**
|
|
1054
|
+
* Returns a new DateTick instance with the given date, keeping the current locale and timezone
|
|
1055
|
+
*
|
|
1056
|
+
* @param {Date | string} date - The date to wrap
|
|
1057
|
+
* @returns {DateTick} The new DateTick
|
|
1058
|
+
* @memberof DateTick
|
|
1059
|
+
*/
|
|
1060
|
+
withDate(date: DateInput): DateTick;
|
|
1061
|
+
/**
|
|
1062
|
+
* Returns a new DateTick instance with the given locale, keeping the current instant and timezone
|
|
1063
|
+
*
|
|
1064
|
+
* @param {string} locale - The BCP 47 locale
|
|
1065
|
+
* @returns {DateTick} The new DateTick
|
|
1066
|
+
* @memberof DateTick
|
|
1067
|
+
*/
|
|
1068
|
+
withLocale(locale: string): DateTick;
|
|
1069
|
+
/**
|
|
1070
|
+
* Returns a new DateTick instance with the given timezone, keeping the same absolute instant
|
|
1071
|
+
* (the wall-clock components will be re-interpreted in the new zone)
|
|
1072
|
+
*
|
|
1073
|
+
* @param {string} timezone - The IANA timezone
|
|
1074
|
+
* @returns {DateTick} The new DateTick
|
|
1075
|
+
* @memberof DateTick
|
|
1076
|
+
*/
|
|
1077
|
+
withTimezone(timezone: string): DateTick;
|
|
1078
|
+
/**
|
|
1079
|
+
* Returns a new DateTick instance with the given first-day-of-week, keeping everything else
|
|
1080
|
+
*
|
|
1081
|
+
* @param {number} weekStartsOn - First day of the week (0 = Sunday … 6 = Saturday)
|
|
1082
|
+
* @returns {DateTick} The new DateTick
|
|
1083
|
+
* @memberof DateTick
|
|
1084
|
+
*/
|
|
1085
|
+
withWeekStart(weekStartsOn: number): DateTick;
|
|
1086
|
+
/**
|
|
1087
|
+
* Gets or sets the year (in the configured timezone)
|
|
1088
|
+
*
|
|
1089
|
+
* @param {number} [value] - The year to set
|
|
1090
|
+
* @returns {number | DateTick} The year, or a new DateTick when setting
|
|
1091
|
+
* @memberof DateTick
|
|
1092
|
+
*/
|
|
1093
|
+
year(): number;
|
|
1094
|
+
year(value: number): DateTick;
|
|
1095
|
+
/** Day.js-style plural alias of {@link DateTick.year}. */
|
|
1096
|
+
years(): number;
|
|
1097
|
+
years(value: number): DateTick;
|
|
1098
|
+
/**
|
|
1099
|
+
* Adds calendar months (used for month/quarter/year), clamping the day to the last valid day.
|
|
1100
|
+
*/
|
|
1101
|
+
private addMonths;
|
|
1102
|
+
private calendarDayNumber;
|
|
1103
|
+
/**
|
|
1104
|
+
* Returns a preset Intl.DateTimeFormatOptions for a given format string.
|
|
1105
|
+
*/
|
|
1106
|
+
private getPreset;
|
|
1107
|
+
/**
|
|
1108
|
+
* The Thursday of this instant's ISO week, as a UTC date built from the zoned calendar date so the
|
|
1109
|
+
* math is offset-free. Shared by {@link DateTick.isoWeek} and {@link DateTick.weekYear}.
|
|
1110
|
+
*/
|
|
1111
|
+
private isoThursday;
|
|
1112
|
+
/**
|
|
1113
|
+
* Creates an adaptive live relative-time stream.
|
|
1114
|
+
*/
|
|
1115
|
+
private liveRelativeTime;
|
|
1116
|
+
/**
|
|
1117
|
+
* Formats the timezone's current offset from UTC as ±HH:mm (with colon) or ±HHmm (without).
|
|
1118
|
+
*/
|
|
1119
|
+
private offsetString;
|
|
1120
|
+
/**
|
|
1121
|
+
* Applies the configured ordinal override, falling back to the English suffix.
|
|
1122
|
+
*/
|
|
1123
|
+
private ordinalFor;
|
|
1124
|
+
/**
|
|
1125
|
+
* Reads the wrapped instant's wall-clock components in the configured timezone.
|
|
1126
|
+
*/
|
|
1127
|
+
private parts;
|
|
1128
|
+
/**
|
|
1129
|
+
* Floating-point calendar-unit difference (used by `diff` when `precise` is true).
|
|
1130
|
+
*
|
|
1131
|
+
* Computes the whole-unit count, then interpolates the fractional remainder between the
|
|
1132
|
+
* instant `whole` units away from `other` and the next unit boundary in the direction of `this`.
|
|
1133
|
+
*/
|
|
1134
|
+
private preciseCalendarDiff;
|
|
1135
|
+
/**
|
|
1136
|
+
* Returns a new DateTick built from the current zoned components with the given overrides applied,
|
|
1137
|
+
* then converted back to an absolute instant in the configured timezone.
|
|
1138
|
+
*/
|
|
1139
|
+
private rebuild;
|
|
1140
|
+
/**
|
|
1141
|
+
* Normalizes a DateInput (Date, string, or DateTick) to a plain Date
|
|
1142
|
+
*/
|
|
1143
|
+
private toComparable;
|
|
1144
|
+
/**
|
|
1145
|
+
* Validates a date and throws an error if invalid
|
|
1146
|
+
*/
|
|
1147
|
+
private validateDate;
|
|
1148
|
+
/**
|
|
1149
|
+
* Number of weeks in this instant's year, per the given week-numbering function: Dec 31 usually
|
|
1150
|
+
* carries the highest week number, unless it rolls into week 1 of the next year (then Dec 24 does).
|
|
1151
|
+
* Shared by {@link DateTick.weeksInYear} and {@link DateTick.isoWeeksInYear}.
|
|
1152
|
+
*/
|
|
1153
|
+
private weeksInYearBy;
|
|
1154
|
+
/**
|
|
1155
|
+
* Whole calendar-month difference (in units of `unitMonths` months), truncated toward zero.
|
|
1156
|
+
*/
|
|
1157
|
+
private wholeMonthDiff;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* Options accepted by the {@link datetick} factory and {@link DateTickFactory.withDefaults}.
|
|
1162
|
+
*/
|
|
1163
|
+
interface DateTickOptions {
|
|
1164
|
+
/** BCP 47 locale used for formatting (default 'en'). */
|
|
1165
|
+
locale?: string;
|
|
1166
|
+
/** IANA timezone all calendar operations resolve through (default: the runtime timezone). */
|
|
1167
|
+
timezone?: string;
|
|
1168
|
+
/** First day of the week, 0 = Sunday … 6 = Saturday (default 0). */
|
|
1169
|
+
weekStartsOn?: number;
|
|
1170
|
+
/** Overrides the English ordinal used by `ordinal()` and the `Do`/`wo`/`Wo` tokens. */
|
|
1171
|
+
ordinal?: OrdinalFn;
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* The callable factory plus its attached static helpers.
|
|
1175
|
+
*/
|
|
1176
|
+
interface DateTickFactory {
|
|
1177
|
+
/**
|
|
1178
|
+
* Creates a {@link DateTick} from a date input.
|
|
1179
|
+
*
|
|
1180
|
+
* @param date - A Date, ISO/parsable string, DateTick, date parts object, or date parts array (defaults to now)
|
|
1181
|
+
* @param options - locale / timezone / weekStartsOn overrides (merged over this factory's defaults)
|
|
1182
|
+
*/
|
|
1183
|
+
(date?: DateInput, options?: DateTickOptions): DateTick;
|
|
1184
|
+
/** Creates a {@link Duration}, using this factory's default locale unless overridden. */
|
|
1185
|
+
duration(value: number | string | DurationInput, unit?: DateUnit, locale?: string): Duration;
|
|
1186
|
+
/** See {@link DateTick.guessTimezone}. */
|
|
1187
|
+
guessTimezone: typeof DateTick.guessTimezone;
|
|
1188
|
+
/** Parses a string into a DateTick, using this factory's default locale/timezone unless overridden. */
|
|
1189
|
+
parse(input: string, pattern: string, locale?: string, timezone?: string): DateTick;
|
|
1190
|
+
/** See {@link DateTick.min}. */
|
|
1191
|
+
min: typeof DateTick.min;
|
|
1192
|
+
/** See {@link DateTick.max}. */
|
|
1193
|
+
max: typeof DateTick.max;
|
|
1194
|
+
/** See {@link DateTick.isValid}. */
|
|
1195
|
+
isValid: typeof DateTick.isValid;
|
|
1196
|
+
/** See {@link DateTick.isDateTick}. */
|
|
1197
|
+
isDateTick: typeof DateTick.isDateTick;
|
|
1198
|
+
/** See {@link Duration.isDuration}. */
|
|
1199
|
+
isDuration: typeof Duration.isDuration;
|
|
1200
|
+
/** Shorthand for `datetick(date, { ...options, timezone: 'UTC' })`. */
|
|
1201
|
+
utc(date?: DateInput, options?: Omit<DateTickOptions, 'timezone'>): DateTick;
|
|
1202
|
+
/** Creates a DateTick from a Unix timestamp in seconds. */
|
|
1203
|
+
unix(seconds: number, options?: DateTickOptions): DateTick;
|
|
1204
|
+
/**
|
|
1205
|
+
* Returns a new, independent factory pre-bound to the given defaults, merged over this
|
|
1206
|
+
* factory's own defaults. Does not mutate this factory or any global state — every part of
|
|
1207
|
+
* an app that wants the same defaults imports the same scoped factory instance.
|
|
1208
|
+
*
|
|
1209
|
+
* @example
|
|
1210
|
+
* const frDateTick = datetick.withDefaults({ locale: 'fr', timezone: 'Europe/Paris' });
|
|
1211
|
+
* frDateTick('2026-06-25').format('long'); // French, Paris
|
|
1212
|
+
* datetick('2026-06-25').format('long'); // unaffected, still 'en' / runtime timezone
|
|
1213
|
+
*/
|
|
1214
|
+
withDefaults(defaults: DateTickOptions): DateTickFactory;
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* The quickest way to create a {@link DateTick}.
|
|
1218
|
+
*
|
|
1219
|
+
* @example
|
|
1220
|
+
* datetick('2026-06-25T19:23Z', { timezone: 'Asia/Tokyo' }).formatPattern('DD/MM/YYYY HH:mm');
|
|
1221
|
+
* datetick.duration(90, 'minute').humanize(); // '2 hours'
|
|
1222
|
+
* datetick.utc('2026-06-25').startOf('week');
|
|
1223
|
+
*/
|
|
1224
|
+
declare const datetick: DateTickFactory;
|
|
1225
|
+
|
|
1226
|
+
export { DateTick, Duration, datetick, datetick as default };
|
|
1227
|
+
export type { CalendarDate, CalendarDiffUnit, CalendarDisplayFormats, CalendarMonth, CalendarMonthOptions, CalendarWeekday, DateArray, DateFormatPreset, DateGettableUnit, DateInput, DateObject, DatePartsObject, DateTickFactory, DateTickOptions, DateUnit, DurationInput, Inclusivity, LocaleData, OrdinalFn, RelativeTimeThresholds, TimeAgoListener, TimeAgoLive };
|