@timestamp-js/core 0.1.0-alpha.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 +75 -0
- package/dist/index.d.ts +980 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1410 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,980 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches supported date and date-time input.
|
|
3
|
+
*
|
|
4
|
+
* Accepts `YYYY-MM`, `YYYY-MM-DD`, space-separated date/time strings,
|
|
5
|
+
* ISO-style `T` separators, optional seconds, optional milliseconds, and
|
|
6
|
+
* optional timezone suffixes such as `Z`, `+06:00`, or `-0700`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PARSE_DATETIME: RegExp;
|
|
9
|
+
/**
|
|
10
|
+
* Matches the date portion of a timestamp string.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PARSE_DATE: RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* Matches `HH`, `HH:mm`, `HH:mm:ss`, or `HH:mm:ss.SSS` time strings.
|
|
15
|
+
*/
|
|
16
|
+
export declare const PARSE_TIME: RegExp;
|
|
17
|
+
/**
|
|
18
|
+
* Month lengths for a non-leap Gregorian year.
|
|
19
|
+
*
|
|
20
|
+
* Index `0` is intentionally unused so month numbers can be used directly.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DAYS_IN_MONTH: number[];
|
|
23
|
+
/**
|
|
24
|
+
* Month lengths for a leap Gregorian year.
|
|
25
|
+
*
|
|
26
|
+
* Index `0` is intentionally unused so month numbers can be used directly.
|
|
27
|
+
*/
|
|
28
|
+
export declare const DAYS_IN_MONTH_LEAP: number[];
|
|
29
|
+
/**
|
|
30
|
+
* Shared conversion constants for milliseconds, seconds, minutes, hours, and days.
|
|
31
|
+
*/
|
|
32
|
+
export declare const TIME_CONSTANTS: {
|
|
33
|
+
MILLISECONDS_IN: {
|
|
34
|
+
SECOND: number;
|
|
35
|
+
MINUTE: number;
|
|
36
|
+
HOUR: number;
|
|
37
|
+
DAY: number;
|
|
38
|
+
WEEK: number;
|
|
39
|
+
};
|
|
40
|
+
SECONDS_IN: {
|
|
41
|
+
MINUTE: number;
|
|
42
|
+
HOUR: number;
|
|
43
|
+
DAY: number;
|
|
44
|
+
WEEK: number;
|
|
45
|
+
};
|
|
46
|
+
MINUTES_IN: {
|
|
47
|
+
MINUTE: number;
|
|
48
|
+
HOUR: number;
|
|
49
|
+
DAY: number;
|
|
50
|
+
WEEK: number;
|
|
51
|
+
};
|
|
52
|
+
HOURS_IN: {
|
|
53
|
+
DAY: number;
|
|
54
|
+
WEEK: number;
|
|
55
|
+
};
|
|
56
|
+
DAYS_IN: {
|
|
57
|
+
WEEK: number;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Minimum number of days found in any Gregorian month.
|
|
62
|
+
*/
|
|
63
|
+
export declare const DAYS_IN_MONTH_MIN = 28;
|
|
64
|
+
/**
|
|
65
|
+
* Maximum number of days found in any Gregorian month.
|
|
66
|
+
*/
|
|
67
|
+
export declare const DAYS_IN_MONTH_MAX = 31;
|
|
68
|
+
/**
|
|
69
|
+
* Maximum Gregorian month number.
|
|
70
|
+
*/
|
|
71
|
+
export declare const MONTH_MAX = 12;
|
|
72
|
+
/**
|
|
73
|
+
* Minimum Gregorian month number.
|
|
74
|
+
*/
|
|
75
|
+
export declare const MONTH_MIN = 1;
|
|
76
|
+
/**
|
|
77
|
+
* Minimum day-of-month number.
|
|
78
|
+
*/
|
|
79
|
+
export declare const DAY_MIN = 1;
|
|
80
|
+
/**
|
|
81
|
+
* First hour in a 24-hour day.
|
|
82
|
+
*/
|
|
83
|
+
export declare const FIRST_HOUR = 0;
|
|
84
|
+
/**
|
|
85
|
+
* Number of days in a week.
|
|
86
|
+
*/
|
|
87
|
+
export declare const DAYS_IN_WEEK: number;
|
|
88
|
+
/**
|
|
89
|
+
* Number of minutes in an hour.
|
|
90
|
+
*/
|
|
91
|
+
export declare const MINUTES_IN_HOUR: number;
|
|
92
|
+
/**
|
|
93
|
+
* Number of hours in a day.
|
|
94
|
+
*/
|
|
95
|
+
export declare const HOURS_IN_DAY: number;
|
|
96
|
+
/**
|
|
97
|
+
* Number of milliseconds in one minute.
|
|
98
|
+
*/
|
|
99
|
+
export declare const MILLISECONDS_IN_MINUTE: number;
|
|
100
|
+
/**
|
|
101
|
+
* Number of milliseconds in one hour.
|
|
102
|
+
*/
|
|
103
|
+
export declare const MILLISECONDS_IN_HOUR: number;
|
|
104
|
+
/**
|
|
105
|
+
* Number of milliseconds in one day.
|
|
106
|
+
*/
|
|
107
|
+
export declare const MILLISECONDS_IN_DAY: number;
|
|
108
|
+
/**
|
|
109
|
+
* Number of milliseconds in one week.
|
|
110
|
+
*/
|
|
111
|
+
export declare const MILLISECONDS_IN_WEEK: number;
|
|
112
|
+
/**
|
|
113
|
+
* Inline style metadata that can be attached to disabled timestamp ranges.
|
|
114
|
+
*/
|
|
115
|
+
export type TimestampStyle = Record<string, string | number | undefined>;
|
|
116
|
+
/**
|
|
117
|
+
* CSS class metadata that can be attached to disabled timestamp ranges.
|
|
118
|
+
*/
|
|
119
|
+
export type TimestampClass = string | string[] | Record<string, boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* Object form for a disabled day or disabled date range.
|
|
122
|
+
*/
|
|
123
|
+
export interface DisabledDayConfig {
|
|
124
|
+
/**
|
|
125
|
+
* Single disabled date in `YYYY-MM-DD` form.
|
|
126
|
+
*/
|
|
127
|
+
date?: string;
|
|
128
|
+
/**
|
|
129
|
+
* Inclusive range start date in `YYYY-MM-DD` form.
|
|
130
|
+
*/
|
|
131
|
+
from?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Inclusive range end date in `YYYY-MM-DD` form.
|
|
134
|
+
*/
|
|
135
|
+
to?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Alias for {@link DisabledDayConfig.from}.
|
|
138
|
+
*/
|
|
139
|
+
start?: string;
|
|
140
|
+
/**
|
|
141
|
+
* Alias for {@link DisabledDayConfig.to}.
|
|
142
|
+
*/
|
|
143
|
+
end?: string;
|
|
144
|
+
/**
|
|
145
|
+
* Optional background color metadata for matching disabled dates.
|
|
146
|
+
*/
|
|
147
|
+
color?: string;
|
|
148
|
+
/**
|
|
149
|
+
* Optional text color metadata for matching disabled dates.
|
|
150
|
+
*/
|
|
151
|
+
textColor?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Optional CSS class metadata for matching disabled dates.
|
|
154
|
+
*/
|
|
155
|
+
class?: TimestampClass;
|
|
156
|
+
/**
|
|
157
|
+
* Optional inline style metadata for matching disabled dates.
|
|
158
|
+
*/
|
|
159
|
+
style?: TimestampStyle;
|
|
160
|
+
/**
|
|
161
|
+
* Optional human-readable label for matching disabled dates.
|
|
162
|
+
*/
|
|
163
|
+
label?: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Supported disabled-day declaration.
|
|
167
|
+
*
|
|
168
|
+
* A string disables a single date, a string array disables multiple dates or
|
|
169
|
+
* an inclusive two-date range, and an object can carry display metadata.
|
|
170
|
+
*/
|
|
171
|
+
export type DisabledDay = string | string[] | DisabledDayConfig;
|
|
172
|
+
/**
|
|
173
|
+
* Collection of disabled-day declarations.
|
|
174
|
+
*/
|
|
175
|
+
export type DisabledDays = DisabledDay[];
|
|
176
|
+
/**
|
|
177
|
+
* Immutable timestamp data used by all parser, comparison, and date math helpers.
|
|
178
|
+
*
|
|
179
|
+
* Timestamps use Gregorian calendar fields and preserve optional ISO timezone
|
|
180
|
+
* suffixes without converting the wall-clock values into another zone.
|
|
181
|
+
*/
|
|
182
|
+
export interface Timestamp {
|
|
183
|
+
/**
|
|
184
|
+
* Date string in `YYYY-MM-DD` form when the timestamp has a day.
|
|
185
|
+
*/
|
|
186
|
+
readonly date: string;
|
|
187
|
+
/**
|
|
188
|
+
* True when the timestamp includes a meaningful date/day value.
|
|
189
|
+
*/
|
|
190
|
+
readonly hasDay: boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Four-digit Gregorian year.
|
|
193
|
+
*/
|
|
194
|
+
readonly year: number;
|
|
195
|
+
/**
|
|
196
|
+
* Gregorian month number, where January is `1` and December is `12`.
|
|
197
|
+
*/
|
|
198
|
+
readonly month: number;
|
|
199
|
+
/**
|
|
200
|
+
* Day of the month.
|
|
201
|
+
*/
|
|
202
|
+
readonly day: number;
|
|
203
|
+
/**
|
|
204
|
+
* Formatted time string.
|
|
205
|
+
*
|
|
206
|
+
* Minute precision is formatted as `HH:mm`; second precision as `HH:mm:ss`;
|
|
207
|
+
* millisecond precision as `HH:mm:ss.SSS`.
|
|
208
|
+
*/
|
|
209
|
+
readonly time?: string;
|
|
210
|
+
/**
|
|
211
|
+
* True when the timestamp includes time fields.
|
|
212
|
+
*/
|
|
213
|
+
readonly hasTime: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Hour in 24-hour format.
|
|
216
|
+
*/
|
|
217
|
+
readonly hour: number;
|
|
218
|
+
/**
|
|
219
|
+
* Minute of the hour.
|
|
220
|
+
*/
|
|
221
|
+
readonly minute: number;
|
|
222
|
+
/**
|
|
223
|
+
* Optional second of the minute.
|
|
224
|
+
*/
|
|
225
|
+
readonly second?: number;
|
|
226
|
+
/**
|
|
227
|
+
* Optional millisecond of the second.
|
|
228
|
+
*/
|
|
229
|
+
readonly millisecond?: number;
|
|
230
|
+
/**
|
|
231
|
+
* Optional parsed ISO timezone suffix such as `Z`, `+06:00`, or `-0700`.
|
|
232
|
+
*
|
|
233
|
+
* The suffix is preserved for callers, but parsing does not convert the
|
|
234
|
+
* wall-clock values into another timezone.
|
|
235
|
+
*/
|
|
236
|
+
readonly timezone?: string;
|
|
237
|
+
/**
|
|
238
|
+
* Weekday number where Sunday is `0` and Saturday is `6`.
|
|
239
|
+
*/
|
|
240
|
+
readonly weekday?: number;
|
|
241
|
+
/**
|
|
242
|
+
* Day of the year.
|
|
243
|
+
*/
|
|
244
|
+
readonly doy?: number;
|
|
245
|
+
/**
|
|
246
|
+
* ISO-style workweek number.
|
|
247
|
+
*/
|
|
248
|
+
readonly workweek?: number;
|
|
249
|
+
/**
|
|
250
|
+
* True when the timestamp is before a comparison timestamp.
|
|
251
|
+
*/
|
|
252
|
+
readonly past?: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* True when the timestamp matches a comparison timestamp.
|
|
255
|
+
*/
|
|
256
|
+
readonly current?: boolean;
|
|
257
|
+
/**
|
|
258
|
+
* True when the timestamp is after a comparison timestamp.
|
|
259
|
+
*/
|
|
260
|
+
readonly future?: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* True when this timestamp represents a disabled date.
|
|
263
|
+
*/
|
|
264
|
+
readonly disabled?: boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Optional background color metadata for a disabled date.
|
|
267
|
+
*/
|
|
268
|
+
readonly disabledColor?: string;
|
|
269
|
+
/**
|
|
270
|
+
* Optional text color metadata for a disabled date.
|
|
271
|
+
*/
|
|
272
|
+
readonly disabledTextColor?: string;
|
|
273
|
+
/**
|
|
274
|
+
* Optional class metadata for a disabled date.
|
|
275
|
+
*/
|
|
276
|
+
readonly disabledClass?: TimestampClass;
|
|
277
|
+
/**
|
|
278
|
+
* Optional inline style metadata for a disabled date.
|
|
279
|
+
*/
|
|
280
|
+
readonly disabledStyle?: TimestampStyle;
|
|
281
|
+
/**
|
|
282
|
+
* Optional human-readable label for a disabled date.
|
|
283
|
+
*/
|
|
284
|
+
readonly disabledLabel?: string;
|
|
285
|
+
/**
|
|
286
|
+
* True when this timestamp's weekday matches a comparison timestamp's weekday.
|
|
287
|
+
*/
|
|
288
|
+
readonly currentWeekday?: boolean;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Time-only value used when callers need hour/minute input without a date.
|
|
292
|
+
*/
|
|
293
|
+
export interface TimeObject {
|
|
294
|
+
/**
|
|
295
|
+
* Hour in 24-hour format.
|
|
296
|
+
*/
|
|
297
|
+
readonly hour: number;
|
|
298
|
+
/**
|
|
299
|
+
* Minute of the hour.
|
|
300
|
+
*/
|
|
301
|
+
readonly minute: number;
|
|
302
|
+
/**
|
|
303
|
+
* Optional second of the minute.
|
|
304
|
+
*/
|
|
305
|
+
readonly second?: number;
|
|
306
|
+
/**
|
|
307
|
+
* Optional millisecond of the second.
|
|
308
|
+
*/
|
|
309
|
+
readonly millisecond?: number;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Frozen empty timestamp template.
|
|
313
|
+
*
|
|
314
|
+
* Use {@link copyTimestamp} or parser helpers to create new timestamp objects
|
|
315
|
+
* instead of mutating this shared default.
|
|
316
|
+
*/
|
|
317
|
+
export declare const Timestamp: Timestamp;
|
|
318
|
+
/**
|
|
319
|
+
* Frozen empty time-object template.
|
|
320
|
+
*/
|
|
321
|
+
export declare const TimeObject: TimeObject;
|
|
322
|
+
/**
|
|
323
|
+
* Validates whether an input string matches the supported timestamp grammar.
|
|
324
|
+
*
|
|
325
|
+
* @param {string} input A string in the form `YYYY-MM-DD`, `YYYY-MM-DD HH:mm`, or a full ISO-like date time.
|
|
326
|
+
* @returns {boolean} True if parseable
|
|
327
|
+
*/
|
|
328
|
+
export declare function validateTimestamp(input: string): boolean;
|
|
329
|
+
/**
|
|
330
|
+
* Fast low-level parser for date and date-time strings.
|
|
331
|
+
*
|
|
332
|
+
* This parser fills numeric fields, but does not update formatted date,
|
|
333
|
+
* weekday, day-of-year, workweek, or relative flags. Use
|
|
334
|
+
* {@link parseTimestamp} when those derived fields are needed.
|
|
335
|
+
*
|
|
336
|
+
* @param {string} input In the form `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like date time with optional milliseconds and timezone suffix.
|
|
337
|
+
* @returns {Timestamp} This {@link Timestamp} is minimally filled in. The {@link Timestamp.date} and {@link Timestamp.time} as well as relative data will not be filled in.
|
|
338
|
+
*/
|
|
339
|
+
export declare function parsed(input: string): Timestamp | null;
|
|
340
|
+
/**
|
|
341
|
+
* Takes a JavaScript Date and returns a {@link Timestamp}. The {@link Timestamp} is not updated with relative information.
|
|
342
|
+
* @param {Date} date JavaScript Date
|
|
343
|
+
* @param {boolean} utc If set the {@link Timestamp} will parse the Date as UTC
|
|
344
|
+
* @returns {Timestamp} A minimal {@link Timestamp} without updated or relative updates.
|
|
345
|
+
*/
|
|
346
|
+
export declare function parseDate(date: Date, utc?: boolean): Timestamp | null;
|
|
347
|
+
/**
|
|
348
|
+
* Pads a number to a requested string length.
|
|
349
|
+
*
|
|
350
|
+
* Useful for formatting values such as `5` as `05`.
|
|
351
|
+
* @param {number} x The number to pad
|
|
352
|
+
* @param {number} length The length of the required number as a string
|
|
353
|
+
* @returns {string} The padded number (as a string). (ie: 5 = '05')
|
|
354
|
+
*/
|
|
355
|
+
export declare function padNumber(x: number, length: number): string;
|
|
356
|
+
/**
|
|
357
|
+
* Returns if the passed year is a leap year
|
|
358
|
+
* @param {number} year The year to check (ie: 1999, 2020)
|
|
359
|
+
* @returns {boolean} True if the year is a leap year
|
|
360
|
+
*/
|
|
361
|
+
export declare function isLeapYear(year: number): boolean;
|
|
362
|
+
/**
|
|
363
|
+
* Returns the days of the specified month in a year
|
|
364
|
+
* @param {number} year The year (ie: 1999, 2020)
|
|
365
|
+
* @param {number} month The Gregorian month number, where January is `1`
|
|
366
|
+
* @returns {number} The number of days in the month (corrected for leap years)
|
|
367
|
+
*/
|
|
368
|
+
export declare function daysInMonth(year: number, month: number): number;
|
|
369
|
+
/**
|
|
370
|
+
* Returns a {@link Timestamp} of next day from passed in {@link Timestamp}
|
|
371
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use
|
|
372
|
+
* @returns {Timestamp} A new {@link Timestamp} representing the next day
|
|
373
|
+
*/
|
|
374
|
+
export declare function nextDay(timestamp: Timestamp): Timestamp;
|
|
375
|
+
/**
|
|
376
|
+
* Returns a {@link Timestamp} of previous day from passed in {@link Timestamp}
|
|
377
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use
|
|
378
|
+
* @returns {Timestamp} A new {@link Timestamp} representing the previous day
|
|
379
|
+
*/
|
|
380
|
+
export declare function prevDay(timestamp: Timestamp): Timestamp;
|
|
381
|
+
/**
|
|
382
|
+
* Returns today's date
|
|
383
|
+
* @returns {string} Date string in the form `YYYY-MM-DD`
|
|
384
|
+
*/
|
|
385
|
+
export declare function today(): string;
|
|
386
|
+
/**
|
|
387
|
+
* Takes a date string ('YYYY-MM-DD') and validates if it is today's date
|
|
388
|
+
* @param {string} date Date string in the form 'YYYY-MM-DD'
|
|
389
|
+
* @returns {boolean} True if the date is today's date
|
|
390
|
+
*/
|
|
391
|
+
export declare function isToday(date: string): boolean;
|
|
392
|
+
/**
|
|
393
|
+
* Returns the start of the week give a {@link Timestamp} and weekdays (in which it finds the day representing the start of the week).
|
|
394
|
+
* If today {@link Timestamp} is passed in then this is used to update relative information in the returned {@link Timestamp}.
|
|
395
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use to find the start of the week
|
|
396
|
+
* @param {number[]} weekdays The array is [0,1,2,3,4,5,6] where 0=Sunday and 6=Saturday
|
|
397
|
+
* @param {Timestamp=} today If passed in then the {@link Timestamp} is updated with relative information
|
|
398
|
+
* @returns {Timestamp} A new {@link Timestamp} representing the start of the week
|
|
399
|
+
*/
|
|
400
|
+
export declare function getStartOfWeek(timestamp: Timestamp, weekdays: number[], today: Timestamp): Timestamp;
|
|
401
|
+
/**
|
|
402
|
+
* Returns the end of the week give a {@link Timestamp} and weekdays (in which it finds the day representing the last of the week).
|
|
403
|
+
* If today {@link Timestamp} is passed in then this is used to update relative information in the returned {@link Timestamp}.
|
|
404
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use to find the end of the week
|
|
405
|
+
* @param {number[]} weekdays The array is [0,1,2,3,4,5,6] where 0=Sunday and 6=Saturday
|
|
406
|
+
* @param {Timestamp=} today If passed in then the {@link Timestamp} is updated with relative information
|
|
407
|
+
* @returns {Timestamp} A new {@link Timestamp} representing the end of the week
|
|
408
|
+
*/
|
|
409
|
+
export declare function getEndOfWeek(timestamp: Timestamp, weekdays: number[], today: Timestamp): Timestamp;
|
|
410
|
+
/**
|
|
411
|
+
* Finds the start of the month based on the passed in {@link Timestamp}
|
|
412
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use to find the start of the month
|
|
413
|
+
* @returns {Timestamp} A {@link Timestamp} of the start of the month
|
|
414
|
+
*/
|
|
415
|
+
export declare function getStartOfMonth(timestamp: Timestamp): Timestamp;
|
|
416
|
+
/**
|
|
417
|
+
* Finds the end of the month based on the passed in {@link Timestamp}
|
|
418
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use to find the end of the month
|
|
419
|
+
* @returns {Timestamp} A {@link Timestamp} of the end of the month
|
|
420
|
+
*/
|
|
421
|
+
export declare function getEndOfMonth(timestamp: Timestamp): Timestamp;
|
|
422
|
+
/**
|
|
423
|
+
* Converts time input into minutes since midnight.
|
|
424
|
+
*
|
|
425
|
+
* Strings may include seconds or milliseconds, but sub-minute precision is
|
|
426
|
+
* ignored for this minute-oriented helper.
|
|
427
|
+
*
|
|
428
|
+
* @param input - Minutes since midnight, a time string, or an object with hour and minute fields.
|
|
429
|
+
* @returns Minutes since midnight, or `false` when the input cannot be parsed.
|
|
430
|
+
*/
|
|
431
|
+
export declare function parseTime(input: number | string | {
|
|
432
|
+
hour: number;
|
|
433
|
+
minute: number;
|
|
434
|
+
}): number | false;
|
|
435
|
+
/**
|
|
436
|
+
* Compares two {@link Timestamp}s for exactness
|
|
437
|
+
* @param {Timestamp} ts1 The first {@link Timestamp}
|
|
438
|
+
* @param {Timestamp} ts2 The second {@link Timestamp}
|
|
439
|
+
* @returns {boolean} True if the two {@link Timestamp}s are an exact match
|
|
440
|
+
*/
|
|
441
|
+
export declare function compareTimestamps(ts1: Timestamp, ts2: Timestamp): boolean;
|
|
442
|
+
/**
|
|
443
|
+
* Compares the date of two {@link Timestamp}s that have been updated with relative data
|
|
444
|
+
* @param {Timestamp} ts1 The first {@link Timestamp}
|
|
445
|
+
* @param {Timestamp} ts2 The second {@link Timestamp}
|
|
446
|
+
* @returns {boolean} True if the two dates are the same
|
|
447
|
+
*/
|
|
448
|
+
export declare function compareDate(ts1: Timestamp, ts2: Timestamp): boolean;
|
|
449
|
+
/**
|
|
450
|
+
* Compares the time of two {@link Timestamp}s that have been updated with relative data
|
|
451
|
+
* @param {Timestamp} ts1 The first {@link Timestamp}
|
|
452
|
+
* @param {Timestamp} ts2 The second {@link Timestamp}
|
|
453
|
+
* @returns {boolean} True if the two times are an exact match
|
|
454
|
+
*/
|
|
455
|
+
export declare function compareTime(ts1: Timestamp, ts2: Timestamp): boolean;
|
|
456
|
+
/**
|
|
457
|
+
* Compares the date and time of two {@link Timestamp}s that have been updated with relative data
|
|
458
|
+
* @param {Timestamp} ts1 The first {@link Timestamp}
|
|
459
|
+
* @param {Timestamp} ts2 The second {@link Timestamp}
|
|
460
|
+
* @returns {boolean} True if the date and time are an exact match
|
|
461
|
+
*/
|
|
462
|
+
export declare function compareDateTime(ts1: Timestamp, ts2: Timestamp): boolean;
|
|
463
|
+
/**
|
|
464
|
+
* High-level parser that converts a string to a fully formatted {@link Timestamp}.
|
|
465
|
+
*
|
|
466
|
+
* If `now` is supplied, the returned timestamp also includes relative flags
|
|
467
|
+
* such as `past`, `current`, `future`, and `currentWeekday`.
|
|
468
|
+
*
|
|
469
|
+
* @param {string} input In the form `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like date time with optional milliseconds and timezone suffix.
|
|
470
|
+
* @param {Timestamp} now A {@link Timestamp} to use for relative data updates
|
|
471
|
+
* @returns {Timestamp} The {@link Timestamp.date} will be filled in as well as the {@link Timestamp.time} if a time is supplied and formatted fields (doy, weekday, workweek, etc). If 'now' is supplied, then relative data will also be updated.
|
|
472
|
+
*/
|
|
473
|
+
export declare function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null;
|
|
474
|
+
/**
|
|
475
|
+
* Converts a {@link Timestamp} into a numeric date identifier based on the passed {@link Timestamp}'s date
|
|
476
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use
|
|
477
|
+
* @returns {number} The numeric date identifier
|
|
478
|
+
*/
|
|
479
|
+
export declare function getDayIdentifier(timestamp: Timestamp): number;
|
|
480
|
+
/**
|
|
481
|
+
* Converts a {@link Timestamp} into a numeric time identifier based on the passed {@link Timestamp}'s time
|
|
482
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use
|
|
483
|
+
* @returns {number} The numeric time identifier
|
|
484
|
+
*/
|
|
485
|
+
export declare function getTimeIdentifier(timestamp: Timestamp): number;
|
|
486
|
+
/**
|
|
487
|
+
* Converts a {@link Timestamp} into a numeric date and time identifier based on the passed {@link Timestamp}'s date and time
|
|
488
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use
|
|
489
|
+
* @returns {number} The numeric date+time identifier
|
|
490
|
+
*/
|
|
491
|
+
export declare function getDayTimeIdentifier(timestamp: Timestamp): number;
|
|
492
|
+
/**
|
|
493
|
+
* Returns the difference between two {@link Timestamp}s
|
|
494
|
+
* @param {Timestamp} ts1 The first {@link Timestamp}
|
|
495
|
+
* @param {Timestamp} ts2 The second {@link Timestamp}
|
|
496
|
+
* @param {boolean=} strict Optional flag to not to return negative numbers
|
|
497
|
+
* @returns {number} The difference
|
|
498
|
+
*/
|
|
499
|
+
export declare function diffTimestamp(ts1: Timestamp, ts2: Timestamp, strict?: boolean): number;
|
|
500
|
+
/**
|
|
501
|
+
* Updates a {@link Timestamp} with relative data (past, current and future)
|
|
502
|
+
* @param {Timestamp} timestamp The {@link Timestamp} that needs relative data updated
|
|
503
|
+
* @param {Timestamp} now {@link Timestamp} that represents the current date (optional time)
|
|
504
|
+
* @param {boolean=} time Optional flag to include time ('timestamp' and 'now' params should have time values)
|
|
505
|
+
* @returns {Timestamp} A new {@link Timestamp}
|
|
506
|
+
*/
|
|
507
|
+
export declare function updateRelative(timestamp: Timestamp, now: Timestamp, time?: boolean): Timestamp;
|
|
508
|
+
/**
|
|
509
|
+
* Returns a timestamp set to a number of minutes past midnight.
|
|
510
|
+
*
|
|
511
|
+
* The returned timestamp has updated hour/minute fields and clears second and
|
|
512
|
+
* millisecond precision because this helper is minute-oriented.
|
|
513
|
+
*
|
|
514
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to transform
|
|
515
|
+
* @param {number} minutes The number of minutes to set from midnight
|
|
516
|
+
* @param {Timestamp=} now Optional {@link Timestamp} representing current date and time
|
|
517
|
+
* @returns {Timestamp} A new {@link Timestamp}
|
|
518
|
+
*/
|
|
519
|
+
export declare function updateMinutes(timestamp: Timestamp, minutes: number, now?: Timestamp | null): Timestamp;
|
|
520
|
+
/**
|
|
521
|
+
* Updates the {@link Timestamp} with the weekday
|
|
522
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to transform
|
|
523
|
+
* @returns A new Timestamp
|
|
524
|
+
*/
|
|
525
|
+
export declare function updateWeekday(timestamp: Timestamp): Timestamp;
|
|
526
|
+
/**
|
|
527
|
+
* Updates the {@link Timestamp} with the day of the year (doy)
|
|
528
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to transform
|
|
529
|
+
* @returns A new Timestamp
|
|
530
|
+
*/
|
|
531
|
+
export declare function updateDayOfYear(timestamp: Timestamp): Timestamp;
|
|
532
|
+
/**
|
|
533
|
+
* Updates the {@link Timestamp} with the workweek
|
|
534
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to transform
|
|
535
|
+
* @returns A new {@link Timestamp}
|
|
536
|
+
*/
|
|
537
|
+
export declare function updateWorkWeek(timestamp: Timestamp): Timestamp;
|
|
538
|
+
/**
|
|
539
|
+
* Updates the passed {@link Timestamp} with disabled, if needed
|
|
540
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to transform
|
|
541
|
+
* @param {string} [disabledBefore] In `YYYY-MM-DD` format
|
|
542
|
+
* @param {string} [disabledAfter] In `YYYY-MM-DD` format
|
|
543
|
+
* @param {number[]} [disabledWeekdays] An array of numbers representing weekdays [0 = Sun, ..., 6 = Sat]
|
|
544
|
+
* @param {DisabledDays} [disabledDays] An array of days in 'YYYY-MM-DD' format. If an array with a pair of dates is in first array, then this is treated as a range. Object entries can include date/from/to plus color metadata.
|
|
545
|
+
* @returns A new {@link Timestamp}
|
|
546
|
+
*/
|
|
547
|
+
export declare function updateDisabled(timestamp: Timestamp, disabledBefore?: string, disabledAfter?: string, disabledWeekdays?: number[], disabledDays?: DisabledDays): Timestamp;
|
|
548
|
+
/**
|
|
549
|
+
* Updates the passed {@link Timestamp} with formatted data (time string, date string, weekday, day of year and workweek)
|
|
550
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to transform
|
|
551
|
+
* @returns A new {@link Timestamp}
|
|
552
|
+
*/
|
|
553
|
+
export declare function updateFormatted(timestamp: Timestamp): Timestamp;
|
|
554
|
+
/**
|
|
555
|
+
* Returns day of the year (doy) for the passed in {@link Timestamp}
|
|
556
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use
|
|
557
|
+
* @returns {number} The day of the year
|
|
558
|
+
*/
|
|
559
|
+
export declare function getDayOfYear(timestamp: Timestamp): number | void;
|
|
560
|
+
/**
|
|
561
|
+
* Returns workweek for the passed in {@link Timestamp}
|
|
562
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use
|
|
563
|
+
* @returns {number} The work week
|
|
564
|
+
*/
|
|
565
|
+
export declare function getWorkWeek(timestamp: Timestamp): number;
|
|
566
|
+
/**
|
|
567
|
+
* Returns weekday for the passed in {@link Timestamp}
|
|
568
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use
|
|
569
|
+
* @returns {number} The weekday
|
|
570
|
+
*/
|
|
571
|
+
export declare function getWeekday(timestamp: Timestamp): number;
|
|
572
|
+
/**
|
|
573
|
+
* Makes a copy of the passed in {@link Timestamp}
|
|
574
|
+
* @param {Timestamp} timestamp The original {@link Timestamp}
|
|
575
|
+
* @returns {Timestamp} A copy of the original {@link Timestamp}
|
|
576
|
+
*/
|
|
577
|
+
export declare function copyTimestamp(timestamp: Timestamp): Timestamp;
|
|
578
|
+
/**
|
|
579
|
+
* Used internally to convert {@link Timestamp} used with 'parsed' or 'parseDate' so the 'date' portion of the {@link Timestamp} is correct.
|
|
580
|
+
* @param {Timestamp} timestamp The (raw) {@link Timestamp}
|
|
581
|
+
* @returns {string} A formatted date ('YYYY-MM-DD')
|
|
582
|
+
*/
|
|
583
|
+
export declare function getDate(timestamp: Timestamp): string;
|
|
584
|
+
/**
|
|
585
|
+
* Used internally to convert {@link Timestamp} with 'parsed' or 'parseDate' so the 'time' portion of the {@link Timestamp} is correct.
|
|
586
|
+
* @param {Timestamp} timestamp The (raw) {@link Timestamp}
|
|
587
|
+
* @returns {string} A formatted time ('hh:mm')
|
|
588
|
+
*/
|
|
589
|
+
export declare function getTime(timestamp: Timestamp): string;
|
|
590
|
+
/**
|
|
591
|
+
* Returns a formatted string date and time ('YYYY-YY-MM hh:mm')
|
|
592
|
+
* @param {Timestamp} timestamp The {@link Timestamp}
|
|
593
|
+
* @returns {string} A formatted date time ('YYYY-MM-DD HH:mm')
|
|
594
|
+
*/
|
|
595
|
+
export declare function getDateTime(timestamp: Timestamp): string;
|
|
596
|
+
/**
|
|
597
|
+
* An alias for {relativeDays}
|
|
598
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to transform
|
|
599
|
+
* @param {function} [mover=nextDay] The mover function to use (ie: {nextDay} or {prevDay}).
|
|
600
|
+
* @param {number} [days=1] The number of days to move.
|
|
601
|
+
* @param {number[]} [allowedWeekdays=[ 0, 1, 2, 3, 4, 5, 6 ]] An array of numbers representing the weekdays. ie: [0 = Sun, ..., 6 = Sat].
|
|
602
|
+
* @returns A new {@link Timestamp}
|
|
603
|
+
*/
|
|
604
|
+
export declare function moveRelativeDays(timestamp: Timestamp, mover?: typeof nextDay, days?: number, allowedWeekdays?: number[]): Timestamp;
|
|
605
|
+
/**
|
|
606
|
+
* Moves the {@link Timestamp} the number of relative days
|
|
607
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to transform
|
|
608
|
+
* @param {function} [mover=nextDay] The mover function to use (ie: {nextDay} or {prevDay}).
|
|
609
|
+
* @param {number} [days=1] The number of days to move.
|
|
610
|
+
* @param {number[]} [allowedWeekdays=[ 0, 1, 2, 3, 4, 5, 6 ]] An array of numbers representing the weekdays. ie: [0 = Sun, ..., 6 = Sat].
|
|
611
|
+
* @returns A new {@link Timestamp}
|
|
612
|
+
*/
|
|
613
|
+
export declare function relativeDays(timestamp: Timestamp, mover?: typeof nextDay, days?: number, allowedWeekdays?: number[]): Timestamp;
|
|
614
|
+
/**
|
|
615
|
+
* Finds the specified weekday (forward or back) based on the {@link Timestamp}
|
|
616
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to transform
|
|
617
|
+
* @param {number} weekday The weekday number (Sun = 0, ..., Sat = 6)
|
|
618
|
+
* @param {function} [mover=nextDay] The function to use ({prevDay} or {nextDay}).
|
|
619
|
+
* @param {number} [maxDays=6] The number of days to look forward or back.
|
|
620
|
+
* @returns A new {@link Timestamp}
|
|
621
|
+
*/
|
|
622
|
+
export declare function findWeekday(timestamp: Timestamp, weekday: number, mover?: typeof nextDay, maxDays?: number): Timestamp;
|
|
623
|
+
/**
|
|
624
|
+
* Creates an array of {@link Timestamp}s based on start and end params
|
|
625
|
+
* @param {Timestamp} start The starting {@link Timestamp}
|
|
626
|
+
* @param {Timestamp} end The ending {@link Timestamp}
|
|
627
|
+
* @param {Timestamp} now The relative day
|
|
628
|
+
* @param {number[]} weekdays An array of numbers (representing days of the week) that are 0 (=Sunday) to 6 (=Saturday)
|
|
629
|
+
* @param {string} [disabledBefore] Days before this date are disabled (YYYY-MM-DD)
|
|
630
|
+
* @param {string} [disabledAfter] Days after this date are disabled (YYYY-MM-DD)
|
|
631
|
+
* @param {number[]} [disabledWeekdays] An array representing weekdays that are disabled [0 = Sun, ..., 6 = Sat]
|
|
632
|
+
* @param {DisabledDays} [disabledDays] An array of days in 'YYYY-MM-DD' format. If an array with a pair of dates is in first array, then this is treated as a range.
|
|
633
|
+
* @param {number} [max=42] Max days to do
|
|
634
|
+
* @param {number} [min=0] Min days to do
|
|
635
|
+
* @returns {Timestamp[]} The requested array of {@link Timestamp}s
|
|
636
|
+
*/
|
|
637
|
+
export declare function createDayList(start: Timestamp, end: Timestamp, now: Timestamp, weekdays?: number[], disabledBefore?: string | undefined, disabledAfter?: string | undefined, disabledWeekdays?: number[], disabledDays?: DisabledDays, max?: number, min?: number): Timestamp[];
|
|
638
|
+
/**
|
|
639
|
+
* Creates an array of interval {@link Timestamp}s based on params
|
|
640
|
+
* @param {Timestamp} timestamp The starting {@link Timestamp}
|
|
641
|
+
* @param {number} first The starting interval time
|
|
642
|
+
* @param {number} minutes How many minutes between intervals (ie: 60, 30, 15 would be common ones)
|
|
643
|
+
* @param {number} count The number of intervals needed
|
|
644
|
+
* @param {Timestamp} now A relative {@link Timestamp} with time
|
|
645
|
+
* @returns {Timestamp[]} The requested array of interval {@link Timestamp}s
|
|
646
|
+
*/
|
|
647
|
+
export declare function createIntervalList(timestamp: Timestamp, first: number, minutes: number, count: number, now: Timestamp): Timestamp[];
|
|
648
|
+
/**
|
|
649
|
+
* Callback that returns `Intl.DateTimeFormat` options for a timestamp.
|
|
650
|
+
*
|
|
651
|
+
* Used by {@link createNativeLocaleFormatter} to let callers switch between
|
|
652
|
+
* long and short formatting styles per timestamp.
|
|
653
|
+
*/
|
|
654
|
+
export type LocaleFormatter = (_timestamp: Timestamp, _short: boolean) => Intl.DateTimeFormatOptions;
|
|
655
|
+
/**
|
|
656
|
+
* Function that formats a weekday key for a locale.
|
|
657
|
+
*/
|
|
658
|
+
export type WeekdayFormatter = (_weekday: keyof typeof weekdayDateMap, _type: string, _locale?: string) => string;
|
|
659
|
+
/**
|
|
660
|
+
* Function that formats a zero-based month number for a locale.
|
|
661
|
+
*/
|
|
662
|
+
export type MonthFormatter = (_month: number, _type?: string, _locale?: string) => string;
|
|
663
|
+
/**
|
|
664
|
+
* @callback getOptions
|
|
665
|
+
* @param {Timestamp} timestamp A {@link Timestamp} object
|
|
666
|
+
* @param {boolean} short True if using short options
|
|
667
|
+
* @returns {Object} An Intl object representing options to be used
|
|
668
|
+
*/
|
|
669
|
+
/**
|
|
670
|
+
* @callback formatter
|
|
671
|
+
* @param {Timestamp} timestamp The {@link Timestamp} being used
|
|
672
|
+
* @param {boolean} short If short format is being requested
|
|
673
|
+
* @returns {string} The localized string of the formatted {@link Timestamp}
|
|
674
|
+
*/
|
|
675
|
+
/**
|
|
676
|
+
* Returns a locale formatter backed by `Intl.DateTimeFormat`.
|
|
677
|
+
*
|
|
678
|
+
* The helper is SSR-safe: if `Intl.DateTimeFormat` is unavailable in a target
|
|
679
|
+
* runtime, it returns a formatter that produces an empty string instead of
|
|
680
|
+
* throwing during module load.
|
|
681
|
+
*
|
|
682
|
+
* @param {string} locale The locale to use (ie: en-US)
|
|
683
|
+
* @param {getOptions} cb The function to call for options. This function should return an Intl formatted object. The function is passed (timestamp, short).
|
|
684
|
+
* @returns {formatter} The function has params (timestamp, short). The short is to use the short options.
|
|
685
|
+
*/
|
|
686
|
+
export declare function createNativeLocaleFormatter(locale: string, cb: LocaleFormatter): (_timestamp: Timestamp, _short: boolean) => string;
|
|
687
|
+
/**
|
|
688
|
+
* Makes a JavaScript Date from the passed {@link Timestamp}
|
|
689
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use
|
|
690
|
+
* @param {boolean} utc True to get Date object using UTC
|
|
691
|
+
* @returns {Date} A JavaScript Date
|
|
692
|
+
*/
|
|
693
|
+
export declare function makeDate(timestamp: Timestamp, utc?: boolean): Date;
|
|
694
|
+
/**
|
|
695
|
+
* Makes a JavaScript Date from the passed {@link Timestamp} (with time)
|
|
696
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to use
|
|
697
|
+
* @param {boolean} utc True to get Date object using UTC
|
|
698
|
+
* @returns {Date} A JavaScript Date
|
|
699
|
+
*/
|
|
700
|
+
export declare function makeDateTime(timestamp: Timestamp, utc?: boolean): Date;
|
|
701
|
+
/**
|
|
702
|
+
* Converts a {@link Timestamp} to a local JavaScript `Date`.
|
|
703
|
+
*
|
|
704
|
+
* This is equivalent to `makeDateTime(timestamp, false)`.
|
|
705
|
+
*
|
|
706
|
+
* @param {Timestamp} timestamp The {@link Timestamp} to convert
|
|
707
|
+
* @returns {Date} A local JavaScript Date
|
|
708
|
+
*/
|
|
709
|
+
export declare function getDateObject(timestamp: Timestamp): Date;
|
|
710
|
+
/**
|
|
711
|
+
* Validates if the input is a finite number.
|
|
712
|
+
*
|
|
713
|
+
* @param input - The value to be validated. Can be a string or a number.
|
|
714
|
+
* @returns A boolean indicating whether the input is a finite number.
|
|
715
|
+
* Returns true if the input is a finite number, false otherwise.
|
|
716
|
+
*/
|
|
717
|
+
export declare function validateNumber(input: string | number): boolean;
|
|
718
|
+
/**
|
|
719
|
+
* Given an array of {@link Timestamp}s, finds the max date (and possible time)
|
|
720
|
+
* @param {Timestamp[]} timestamps This is an array of {@link Timestamp}s
|
|
721
|
+
* @param {boolean=} useTime Default false; if true, uses time in the comparison as well
|
|
722
|
+
* @returns The {@link Timestamp} with the highest date (and possibly time) value
|
|
723
|
+
*/
|
|
724
|
+
export declare function maxTimestamp(timestamps: Timestamp[], useTime?: boolean): Timestamp;
|
|
725
|
+
/**
|
|
726
|
+
* Given an array of {@link Timestamp}s, finds the min date (and possible time)
|
|
727
|
+
* @param {Timestamp[]} timestamps This is an array of {@link Timestamp}s
|
|
728
|
+
* @param {boolean=} useTime Default false; if true, uses time in the comparison as well
|
|
729
|
+
* @returns The {@link Timestamp} with the lowest date (and possibly time) value
|
|
730
|
+
*/
|
|
731
|
+
export declare function minTimestamp(timestamps: Timestamp[], useTime?: boolean): Timestamp;
|
|
732
|
+
/**
|
|
733
|
+
* Determines if the passed {@link Timestamp} is between (or equal) to two {@link Timestamp}s (range)
|
|
734
|
+
* @param {Timestamp} timestamp The {@link Timestamp} for testing
|
|
735
|
+
* @param {Timestamp} startTimestamp The starting {@link Timestamp}
|
|
736
|
+
* @param {Timestamp} endTimestamp The ending {@link Timestamp}
|
|
737
|
+
* @param {boolean=} useTime If true, use time from the {@link Timestamp}s
|
|
738
|
+
* @returns {boolean} True if {@link Timestamp} is between (or equal) to two {@link Timestamp}s (range)
|
|
739
|
+
*/
|
|
740
|
+
export declare function isBetweenDates(timestamp: Timestamp, startTimestamp: Timestamp, endTimestamp: Timestamp, useTime?: boolean): boolean;
|
|
741
|
+
/**
|
|
742
|
+
* Determine if two ranges of {@link Timestamp}s overlap each other
|
|
743
|
+
* @param {Timestamp} startTimestamp The starting {@link Timestamp} of first range
|
|
744
|
+
* @param {Timestamp} endTimestamp The endinging {@link Timestamp} of first range
|
|
745
|
+
* @param {Timestamp} firstTimestamp The starting {@link Timestamp} of second range
|
|
746
|
+
* @param {Timestamp} lastTimestamp The ending {@link Timestamp} of second range
|
|
747
|
+
* @returns {boolean} True if the two ranges overlap each other
|
|
748
|
+
*/
|
|
749
|
+
export declare function isOverlappingDates(startTimestamp: Timestamp, endTimestamp: Timestamp, firstTimestamp: Timestamp, lastTimestamp: Timestamp): boolean;
|
|
750
|
+
/**
|
|
751
|
+
* Date and time offsets accepted by {@link addToDate}.
|
|
752
|
+
*
|
|
753
|
+
* Positive values add time; negative values subtract time. The result is
|
|
754
|
+
* normalized through JavaScript Date rules, so overflowing months, days,
|
|
755
|
+
* seconds, or milliseconds roll into adjacent fields.
|
|
756
|
+
*/
|
|
757
|
+
export interface AddToDateOptions {
|
|
758
|
+
/**
|
|
759
|
+
* Number of years to add or subtract.
|
|
760
|
+
*/
|
|
761
|
+
year?: number;
|
|
762
|
+
/**
|
|
763
|
+
* Number of months to add or subtract.
|
|
764
|
+
*/
|
|
765
|
+
month?: number;
|
|
766
|
+
/**
|
|
767
|
+
* Number of days to add or subtract.
|
|
768
|
+
*/
|
|
769
|
+
day?: number;
|
|
770
|
+
/**
|
|
771
|
+
* Number of hours to add or subtract.
|
|
772
|
+
*/
|
|
773
|
+
hour?: number;
|
|
774
|
+
/**
|
|
775
|
+
* Number of minutes to add or subtract.
|
|
776
|
+
*/
|
|
777
|
+
minute?: number;
|
|
778
|
+
/**
|
|
779
|
+
* Number of seconds to add or subtract.
|
|
780
|
+
*/
|
|
781
|
+
second?: number;
|
|
782
|
+
/**
|
|
783
|
+
* Number of milliseconds to add or subtract.
|
|
784
|
+
*/
|
|
785
|
+
millisecond?: number;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Adds or subtracts date/time units from a timestamp.
|
|
789
|
+
*
|
|
790
|
+
* This function returns a new frozen {@link Timestamp}; it does not mutate the
|
|
791
|
+
* timestamp passed in.
|
|
792
|
+
*
|
|
793
|
+
* @param {Timestamp} timestamp The {@link Timestamp} object
|
|
794
|
+
* @param {Object} options configuration data
|
|
795
|
+
* @param {number=} options.year If positive, adds years. If negative, removes years.
|
|
796
|
+
* @param {number=} options.month If positive, adds months. If negative, removes month.
|
|
797
|
+
* @param {number=} options.day If positive, adds days. If negative, removes days.
|
|
798
|
+
* @param {number=} options.hour If positive, adds hours. If negative, removes hours.
|
|
799
|
+
* @param {number=} options.minute If positive, adds minutes. If negative, removes minutes.
|
|
800
|
+
* @param {number=} options.second If positive, adds seconds. If negative, removes seconds.
|
|
801
|
+
* @param {number=} options.millisecond If positive, adds milliseconds. If negative, removes milliseconds.
|
|
802
|
+
* @returns {Timestamp} A new normalized {@link Timestamp}
|
|
803
|
+
*/
|
|
804
|
+
export declare function addToDate(timestamp: Timestamp, options: AddToDateOptions): Timestamp;
|
|
805
|
+
/**
|
|
806
|
+
* Returns number of days between two {@link Timestamp}s
|
|
807
|
+
* @param {Timestamp} ts1 The first {@link Timestamp}
|
|
808
|
+
* @param {Timestamp} ts2 The second {@link Timestamp}
|
|
809
|
+
* @returns Number of days
|
|
810
|
+
*/
|
|
811
|
+
export declare function daysBetween(ts1: Timestamp, ts2: Timestamp): number;
|
|
812
|
+
/**
|
|
813
|
+
* Returns number of weeks between two {@link Timestamp}s
|
|
814
|
+
* @param {Timestamp} ts1 The first {@link Timestamp}
|
|
815
|
+
* @param {Timestamp} ts2 The second {@link Timestamp}
|
|
816
|
+
*/
|
|
817
|
+
export declare function weeksBetween(ts1: Timestamp, ts2: Timestamp): number;
|
|
818
|
+
declare const weekdayDateMap: {
|
|
819
|
+
Sun: Date;
|
|
820
|
+
Mon: Date;
|
|
821
|
+
Tue: Date;
|
|
822
|
+
Wed: Date;
|
|
823
|
+
Thu: Date;
|
|
824
|
+
Fri: Date;
|
|
825
|
+
Sat: Date;
|
|
826
|
+
};
|
|
827
|
+
/**
|
|
828
|
+
* Returns a function that uses Intl.DateTimeFormat to format weekdays.
|
|
829
|
+
*
|
|
830
|
+
* @function getWeekdayFormatter
|
|
831
|
+
* @returns {function} A function that formats weekdays.
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* const formatWeekday = getWeekdayFormatter();
|
|
835
|
+
* console.log(formatWeekday('Mon', 'long', 'en-US')); // "Monday"
|
|
836
|
+
* console.log(formatWeekday('Mon', 'short', 'fr-FR')); // "lun."
|
|
837
|
+
*
|
|
838
|
+
* @param {string} weekday - The abbreviation of the weekday (e.g., 'Mon', 'Tue', 'Wed', etc.).
|
|
839
|
+
* @param {string} [type='long'] - The type of formatting to use ('narrow', 'short', or 'long').
|
|
840
|
+
* @param {string} [locale=''] - The locale to use for formatting.
|
|
841
|
+
*
|
|
842
|
+
* @returns {string} The formatted weekday.
|
|
843
|
+
*/
|
|
844
|
+
export declare function getWeekdayFormatter(): WeekdayFormatter;
|
|
845
|
+
/**
|
|
846
|
+
* Retrieves an array of localized weekday names.
|
|
847
|
+
*
|
|
848
|
+
* @param {string} type - The format type for the weekday names. Can be 'narrow', 'short', or 'long'.
|
|
849
|
+
* @param {string} [locale] - The locale to use for formatting. If not provided, the default locale is used.
|
|
850
|
+
* @returns {string[]} An array of localized weekday names in the specified format.
|
|
851
|
+
*/
|
|
852
|
+
export declare function getWeekdayNames(type: string, locale: string): string[];
|
|
853
|
+
/**
|
|
854
|
+
* Creates and returns a function for formatting month names based on locale and format type.
|
|
855
|
+
*
|
|
856
|
+
* @returns {Function} A function that formats month names.
|
|
857
|
+
* The returned function accepts the following parameters:
|
|
858
|
+
* @param {number} month - The month to format (0-11, where 0 is January).
|
|
859
|
+
* @param {string} [type='long'] - The format type: 'narrow', 'short', or 'long'.
|
|
860
|
+
* @param {string} [locale] - The locale to use for formatting. If not provided, the default locale is used.
|
|
861
|
+
* @returns {string} The formatted month name.
|
|
862
|
+
*
|
|
863
|
+
* @throws {Error} If Intl or Intl.DateTimeFormat is not supported in the environment.
|
|
864
|
+
*/
|
|
865
|
+
export declare function getMonthFormatter(): MonthFormatter;
|
|
866
|
+
/**
|
|
867
|
+
* Retrieves an array of localized month names.
|
|
868
|
+
*
|
|
869
|
+
* @param {string} type - The format type for the month names. Can be 'narrow', 'short', or 'long'.
|
|
870
|
+
* @param {string} [locale] - The locale to use for formatting. If not provided, the default locale is used.
|
|
871
|
+
* @returns {string[]} An array of localized month names in the specified format.
|
|
872
|
+
*/
|
|
873
|
+
export declare function getMonthNames(type: string, locale: string): string[];
|
|
874
|
+
declare const _default: {
|
|
875
|
+
PARSE_DATETIME: RegExp;
|
|
876
|
+
PARSE_DATE: RegExp;
|
|
877
|
+
PARSE_TIME: RegExp;
|
|
878
|
+
DAYS_IN_MONTH: number[];
|
|
879
|
+
DAYS_IN_MONTH_LEAP: number[];
|
|
880
|
+
DAYS_IN_MONTH_MIN: number;
|
|
881
|
+
DAYS_IN_MONTH_MAX: number;
|
|
882
|
+
MONTH_MAX: number;
|
|
883
|
+
MONTH_MIN: number;
|
|
884
|
+
DAY_MIN: number;
|
|
885
|
+
TIME_CONSTANTS: {
|
|
886
|
+
MILLISECONDS_IN: {
|
|
887
|
+
SECOND: number;
|
|
888
|
+
MINUTE: number;
|
|
889
|
+
HOUR: number;
|
|
890
|
+
DAY: number;
|
|
891
|
+
WEEK: number;
|
|
892
|
+
};
|
|
893
|
+
SECONDS_IN: {
|
|
894
|
+
MINUTE: number;
|
|
895
|
+
HOUR: number;
|
|
896
|
+
DAY: number;
|
|
897
|
+
WEEK: number;
|
|
898
|
+
};
|
|
899
|
+
MINUTES_IN: {
|
|
900
|
+
MINUTE: number;
|
|
901
|
+
HOUR: number;
|
|
902
|
+
DAY: number;
|
|
903
|
+
WEEK: number;
|
|
904
|
+
};
|
|
905
|
+
HOURS_IN: {
|
|
906
|
+
DAY: number;
|
|
907
|
+
WEEK: number;
|
|
908
|
+
};
|
|
909
|
+
DAYS_IN: {
|
|
910
|
+
WEEK: number;
|
|
911
|
+
};
|
|
912
|
+
};
|
|
913
|
+
DAYS_IN_WEEK: number;
|
|
914
|
+
MINUTES_IN_HOUR: number;
|
|
915
|
+
HOURS_IN_DAY: number;
|
|
916
|
+
FIRST_HOUR: number;
|
|
917
|
+
MILLISECONDS_IN_MINUTE: number;
|
|
918
|
+
MILLISECONDS_IN_HOUR: number;
|
|
919
|
+
MILLISECONDS_IN_DAY: number;
|
|
920
|
+
MILLISECONDS_IN_WEEK: number;
|
|
921
|
+
Timestamp: Timestamp;
|
|
922
|
+
TimeObject: TimeObject;
|
|
923
|
+
today: typeof today;
|
|
924
|
+
getStartOfWeek: typeof getStartOfWeek;
|
|
925
|
+
getEndOfWeek: typeof getEndOfWeek;
|
|
926
|
+
getStartOfMonth: typeof getStartOfMonth;
|
|
927
|
+
getEndOfMonth: typeof getEndOfMonth;
|
|
928
|
+
parseTime: typeof parseTime;
|
|
929
|
+
validateTimestamp: typeof validateTimestamp;
|
|
930
|
+
parsed: typeof parsed;
|
|
931
|
+
parseTimestamp: typeof parseTimestamp;
|
|
932
|
+
parseDate: typeof parseDate;
|
|
933
|
+
getDayIdentifier: typeof getDayIdentifier;
|
|
934
|
+
getTimeIdentifier: typeof getTimeIdentifier;
|
|
935
|
+
getDayTimeIdentifier: typeof getDayTimeIdentifier;
|
|
936
|
+
diffTimestamp: typeof diffTimestamp;
|
|
937
|
+
updateRelative: typeof updateRelative;
|
|
938
|
+
updateMinutes: typeof updateMinutes;
|
|
939
|
+
updateWeekday: typeof updateWeekday;
|
|
940
|
+
updateDayOfYear: typeof updateDayOfYear;
|
|
941
|
+
updateWorkWeek: typeof updateWorkWeek;
|
|
942
|
+
updateDisabled: typeof updateDisabled;
|
|
943
|
+
updateFormatted: typeof updateFormatted;
|
|
944
|
+
getDayOfYear: typeof getDayOfYear;
|
|
945
|
+
getWorkWeek: typeof getWorkWeek;
|
|
946
|
+
getWeekday: typeof getWeekday;
|
|
947
|
+
isLeapYear: typeof isLeapYear;
|
|
948
|
+
daysInMonth: typeof daysInMonth;
|
|
949
|
+
copyTimestamp: typeof copyTimestamp;
|
|
950
|
+
padNumber: typeof padNumber;
|
|
951
|
+
getDate: typeof getDate;
|
|
952
|
+
getTime: typeof getTime;
|
|
953
|
+
getDateTime: typeof getDateTime;
|
|
954
|
+
nextDay: typeof nextDay;
|
|
955
|
+
prevDay: typeof prevDay;
|
|
956
|
+
relativeDays: typeof relativeDays;
|
|
957
|
+
findWeekday: typeof findWeekday;
|
|
958
|
+
createDayList: typeof createDayList;
|
|
959
|
+
createIntervalList: typeof createIntervalList;
|
|
960
|
+
createNativeLocaleFormatter: typeof createNativeLocaleFormatter;
|
|
961
|
+
makeDate: typeof makeDate;
|
|
962
|
+
makeDateTime: typeof makeDateTime;
|
|
963
|
+
getDateObject: typeof getDateObject;
|
|
964
|
+
validateNumber: typeof validateNumber;
|
|
965
|
+
isBetweenDates: typeof isBetweenDates;
|
|
966
|
+
isOverlappingDates: typeof isOverlappingDates;
|
|
967
|
+
daysBetween: typeof daysBetween;
|
|
968
|
+
weeksBetween: typeof weeksBetween;
|
|
969
|
+
addToDate: typeof addToDate;
|
|
970
|
+
compareTimestamps: typeof compareTimestamps;
|
|
971
|
+
compareDate: typeof compareDate;
|
|
972
|
+
compareTime: typeof compareTime;
|
|
973
|
+
compareDateTime: typeof compareDateTime;
|
|
974
|
+
getWeekdayFormatter: typeof getWeekdayFormatter;
|
|
975
|
+
getWeekdayNames: typeof getWeekdayNames;
|
|
976
|
+
getMonthFormatter: typeof getMonthFormatter;
|
|
977
|
+
getMonthNames: typeof getMonthNames;
|
|
978
|
+
};
|
|
979
|
+
export default _default;
|
|
980
|
+
//# sourceMappingURL=index.d.ts.map
|