ts-time-utils 3.0.4 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +186 -6
  2. package/dist/calculate.d.ts +25 -0
  3. package/dist/calculate.d.ts.map +1 -1
  4. package/dist/calculate.js +125 -0
  5. package/dist/calendar.d.ts +45 -0
  6. package/dist/calendar.d.ts.map +1 -1
  7. package/dist/calendar.js +68 -0
  8. package/dist/calendars.d.ts +156 -0
  9. package/dist/calendars.d.ts.map +1 -0
  10. package/dist/calendars.js +348 -0
  11. package/dist/compare.d.ts +27 -0
  12. package/dist/compare.d.ts.map +1 -1
  13. package/dist/compare.js +46 -0
  14. package/dist/esm/calculate.d.ts +25 -0
  15. package/dist/esm/calculate.d.ts.map +1 -1
  16. package/dist/esm/calculate.js +125 -0
  17. package/dist/esm/calendar.d.ts +45 -0
  18. package/dist/esm/calendar.d.ts.map +1 -1
  19. package/dist/esm/calendar.js +68 -0
  20. package/dist/esm/calendars.d.ts +156 -0
  21. package/dist/esm/calendars.d.ts.map +1 -0
  22. package/dist/esm/calendars.js +348 -0
  23. package/dist/esm/compare.d.ts +27 -0
  24. package/dist/esm/compare.d.ts.map +1 -1
  25. package/dist/esm/compare.js +46 -0
  26. package/dist/esm/finance.d.ts +236 -0
  27. package/dist/esm/finance.d.ts.map +1 -0
  28. package/dist/esm/finance.js +495 -0
  29. package/dist/esm/healthcare.d.ts +260 -0
  30. package/dist/esm/healthcare.d.ts.map +1 -0
  31. package/dist/esm/healthcare.js +447 -0
  32. package/dist/esm/holidays.d.ts +11 -1
  33. package/dist/esm/holidays.d.ts.map +1 -1
  34. package/dist/esm/holidays.js +220 -1
  35. package/dist/esm/index.d.ts +19 -7
  36. package/dist/esm/index.d.ts.map +1 -1
  37. package/dist/esm/index.js +23 -9
  38. package/dist/esm/iterate.d.ts +55 -0
  39. package/dist/esm/iterate.d.ts.map +1 -1
  40. package/dist/esm/iterate.js +86 -0
  41. package/dist/esm/locale.d.ts +53 -0
  42. package/dist/esm/locale.d.ts.map +1 -1
  43. package/dist/esm/locale.js +141 -0
  44. package/dist/esm/precision.d.ts +225 -0
  45. package/dist/esm/precision.d.ts.map +1 -0
  46. package/dist/esm/precision.js +491 -0
  47. package/dist/esm/scheduling.d.ts +206 -0
  48. package/dist/esm/scheduling.d.ts.map +1 -0
  49. package/dist/esm/scheduling.js +329 -0
  50. package/dist/esm/temporal.d.ts +237 -0
  51. package/dist/esm/temporal.d.ts.map +1 -0
  52. package/dist/esm/temporal.js +660 -0
  53. package/dist/esm/validate.d.ts +30 -0
  54. package/dist/esm/validate.d.ts.map +1 -1
  55. package/dist/esm/validate.js +48 -0
  56. package/dist/finance.d.ts +236 -0
  57. package/dist/finance.d.ts.map +1 -0
  58. package/dist/finance.js +495 -0
  59. package/dist/healthcare.d.ts +260 -0
  60. package/dist/healthcare.d.ts.map +1 -0
  61. package/dist/healthcare.js +447 -0
  62. package/dist/holidays.d.ts +11 -1
  63. package/dist/holidays.d.ts.map +1 -1
  64. package/dist/holidays.js +220 -1
  65. package/dist/index.d.ts +19 -7
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +23 -9
  68. package/dist/iterate.d.ts +55 -0
  69. package/dist/iterate.d.ts.map +1 -1
  70. package/dist/iterate.js +86 -0
  71. package/dist/locale.d.ts +53 -0
  72. package/dist/locale.d.ts.map +1 -1
  73. package/dist/locale.js +141 -0
  74. package/dist/precision.d.ts +225 -0
  75. package/dist/precision.d.ts.map +1 -0
  76. package/dist/precision.js +491 -0
  77. package/dist/scheduling.d.ts +206 -0
  78. package/dist/scheduling.d.ts.map +1 -0
  79. package/dist/scheduling.js +329 -0
  80. package/dist/temporal.d.ts +237 -0
  81. package/dist/temporal.d.ts.map +1 -0
  82. package/dist/temporal.js +660 -0
  83. package/dist/validate.d.ts +30 -0
  84. package/dist/validate.d.ts.map +1 -1
  85. package/dist/validate.js +48 -0
  86. package/package.json +31 -1
@@ -0,0 +1,329 @@
1
+ /**
2
+ * @fileoverview Scheduling and booking utilities
3
+ * Provides slot generation, availability checking, and conflict detection
4
+ */
5
+ import { dateRangeOverlap, mergeDateRanges } from './dateRange.js';
6
+ import { isWorkingDay, isWorkingTime, DEFAULT_WORKING_HOURS, getWorkDayStart, getWorkDayEnd } from './workingHours.js';
7
+ import { getOccurrencesBetween } from './recurrence.js';
8
+ /** Default scheduling configuration */
9
+ export const DEFAULT_SCHEDULING_CONFIG = {
10
+ workingHours: DEFAULT_WORKING_HOURS,
11
+ bufferMinutes: 0,
12
+ slotDuration: 30,
13
+ holidays: []
14
+ };
15
+ /**
16
+ * Helper to convert DateInput to Date
17
+ */
18
+ function toDate(input) {
19
+ if (input instanceof Date)
20
+ return new Date(input);
21
+ return new Date(input);
22
+ }
23
+ /**
24
+ * Check if a date is a holiday
25
+ */
26
+ function isHoliday(date, holidays) {
27
+ const dateStr = date.toISOString().split('T')[0];
28
+ return holidays.some(h => h.toISOString().split('T')[0] === dateStr);
29
+ }
30
+ /**
31
+ * Generates time slots for a single day
32
+ * @param date - The date to generate slots for
33
+ * @param config - Scheduling configuration
34
+ * @returns Array of slots for the day
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const slots = generateSlots(new Date('2024-01-15'), { slotDuration: 30 });
39
+ * // Returns 30-minute slots during working hours
40
+ * ```
41
+ */
42
+ export function generateSlots(date, config = {}) {
43
+ const d = toDate(date);
44
+ const cfg = { ...DEFAULT_SCHEDULING_CONFIG, ...config };
45
+ const workingHours = cfg.workingHours ?? DEFAULT_WORKING_HOURS;
46
+ // Check if it's a working day and not a holiday
47
+ if (!isWorkingDay(d, workingHours))
48
+ return [];
49
+ if (cfg.holidays && isHoliday(d, cfg.holidays))
50
+ return [];
51
+ const slots = [];
52
+ const slotDuration = cfg.slotDuration ?? 30;
53
+ const dayStart = getWorkDayStart(d, workingHours);
54
+ const dayEnd = getWorkDayEnd(d, workingHours);
55
+ let current = new Date(dayStart);
56
+ while (current < dayEnd) {
57
+ const slotEnd = new Date(current.getTime() + slotDuration * 60 * 1000);
58
+ // Don't create slots that extend past working hours
59
+ if (slotEnd <= dayEnd) {
60
+ // Check if slot is during working time (not during breaks)
61
+ const midpoint = new Date(current.getTime() + (slotDuration * 60 * 1000) / 2);
62
+ const available = isWorkingTime(midpoint, workingHours);
63
+ slots.push({
64
+ start: new Date(current),
65
+ end: new Date(slotEnd),
66
+ available
67
+ });
68
+ }
69
+ current = slotEnd;
70
+ }
71
+ return slots;
72
+ }
73
+ /**
74
+ * Generates time slots for a date range
75
+ * @param range - The date range to generate slots for
76
+ * @param config - Scheduling configuration
77
+ * @returns Array of slots for all days in range
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const range = { start: new Date('2024-01-15'), end: new Date('2024-01-17') };
82
+ * const slots = generateSlotsForRange(range, { slotDuration: 60 });
83
+ * ```
84
+ */
85
+ export function generateSlotsForRange(range, config = {}) {
86
+ const slots = [];
87
+ const current = new Date(range.start);
88
+ current.setHours(0, 0, 0, 0);
89
+ const endDate = new Date(range.end);
90
+ endDate.setHours(23, 59, 59, 999);
91
+ while (current <= endDate) {
92
+ const daySlots = generateSlots(current, config);
93
+ slots.push(...daySlots);
94
+ current.setDate(current.getDate() + 1);
95
+ }
96
+ return slots;
97
+ }
98
+ /**
99
+ * Gets available slots for a day, excluding existing bookings
100
+ * @param date - The date to check
101
+ * @param bookings - Existing bookings
102
+ * @param config - Scheduling configuration
103
+ * @returns Array of available slots
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const bookings = [{ start: new Date('2024-01-15T10:00'), end: new Date('2024-01-15T11:00') }];
108
+ * const available = getAvailableSlots(new Date('2024-01-15'), bookings);
109
+ * ```
110
+ */
111
+ export function getAvailableSlots(date, bookings, config = {}) {
112
+ const cfg = { ...DEFAULT_SCHEDULING_CONFIG, ...config };
113
+ const slots = generateSlots(date, cfg);
114
+ const bufferMs = (cfg.bufferMinutes ?? 0) * 60 * 1000;
115
+ return slots.map(slot => {
116
+ // Expand slot by buffer for conflict checking
117
+ const checkRange = {
118
+ start: new Date(slot.start.getTime() - bufferMs),
119
+ end: new Date(slot.end.getTime() + bufferMs)
120
+ };
121
+ const hasConflict = bookings.some(booking => dateRangeOverlap(checkRange, booking));
122
+ return {
123
+ ...slot,
124
+ available: slot.available && !hasConflict
125
+ };
126
+ });
127
+ }
128
+ /**
129
+ * Finds the next available slot of specified duration
130
+ * @param after - Start searching after this date
131
+ * @param bookings - Existing bookings
132
+ * @param duration - Required slot duration in minutes
133
+ * @param config - Scheduling configuration
134
+ * @returns Next available slot or null if none found within 30 days
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * const nextSlot = findNextAvailable(new Date(), bookings, 60);
139
+ * if (nextSlot) console.log(`Next 1-hour slot at ${nextSlot.start}`);
140
+ * ```
141
+ */
142
+ export function findNextAvailable(after, bookings, duration, config = {}) {
143
+ const startDate = toDate(after);
144
+ const cfg = { ...DEFAULT_SCHEDULING_CONFIG, ...config, slotDuration: duration };
145
+ // Search up to 30 days ahead
146
+ for (let dayOffset = 0; dayOffset < 30; dayOffset++) {
147
+ const checkDate = new Date(startDate);
148
+ checkDate.setDate(checkDate.getDate() + dayOffset);
149
+ const availableSlots = getAvailableSlots(checkDate, bookings, cfg);
150
+ for (const slot of availableSlots) {
151
+ if (slot.available && slot.start >= startDate) {
152
+ return slot;
153
+ }
154
+ }
155
+ }
156
+ return null;
157
+ }
158
+ /**
159
+ * Checks if a slot is available (no conflicts with existing bookings)
160
+ * @param slot - The slot to check
161
+ * @param bookings - Existing bookings
162
+ * @returns True if slot is available
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * const slot = { start: new Date('2024-01-15T14:00'), end: new Date('2024-01-15T15:00') };
167
+ * if (isSlotAvailable(slot, existingBookings)) {
168
+ * // Book the slot
169
+ * }
170
+ * ```
171
+ */
172
+ export function isSlotAvailable(slot, bookings) {
173
+ return !bookings.some(booking => dateRangeOverlap(slot, booking));
174
+ }
175
+ /**
176
+ * Finds bookings that conflict with a proposed time range
177
+ * @param bookings - Existing bookings
178
+ * @param proposed - Proposed time range
179
+ * @returns Array of conflicting bookings
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * const conflicts = findConflicts(existingBookings, { start: propStart, end: propEnd });
184
+ * if (conflicts.length > 0) {
185
+ * console.log('Conflicts with:', conflicts);
186
+ * }
187
+ * ```
188
+ */
189
+ export function findConflicts(bookings, proposed) {
190
+ return bookings.filter(booking => dateRangeOverlap(booking, proposed));
191
+ }
192
+ /**
193
+ * Checks if a proposed time range has any conflicts
194
+ * @param bookings - Existing bookings
195
+ * @param proposed - Proposed time range
196
+ * @returns True if there are conflicts
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * if (hasConflict(existingBookings, proposedMeeting)) {
201
+ * console.log('Time slot not available');
202
+ * }
203
+ * ```
204
+ */
205
+ export function hasConflict(bookings, proposed) {
206
+ return bookings.some(booking => dateRangeOverlap(booking, proposed));
207
+ }
208
+ /**
209
+ * Adds buffer time around a slot
210
+ * @param slot - The original slot
211
+ * @param bufferMinutes - Buffer time in minutes
212
+ * @returns New slot with buffer added
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * const slot = { start: new Date('2024-01-15T10:00'), end: new Date('2024-01-15T11:00') };
217
+ * const buffered = addBuffer(slot, 15);
218
+ * // buffered.start = 09:45, buffered.end = 11:15
219
+ * ```
220
+ */
221
+ export function addBuffer(slot, bufferMinutes) {
222
+ const bufferMs = bufferMinutes * 60 * 1000;
223
+ return {
224
+ start: new Date(slot.start.getTime() - bufferMs),
225
+ end: new Date(slot.end.getTime() + bufferMs)
226
+ };
227
+ }
228
+ /**
229
+ * Removes buffer time from a slot
230
+ * @param slot - The buffered slot
231
+ * @param bufferMinutes - Buffer time in minutes to remove
232
+ * @returns New slot with buffer removed
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * const bufferedSlot = { start: new Date('2024-01-15T09:45'), end: new Date('2024-01-15T11:15') };
237
+ * const original = removeBuffer(bufferedSlot, 15);
238
+ * // original.start = 10:00, original.end = 11:00
239
+ * ```
240
+ */
241
+ export function removeBuffer(slot, bufferMinutes) {
242
+ const bufferMs = bufferMinutes * 60 * 1000;
243
+ return {
244
+ start: new Date(slot.start.getTime() + bufferMs),
245
+ end: new Date(slot.end.getTime() - bufferMs)
246
+ };
247
+ }
248
+ /**
249
+ * Expands recurring availability pattern into concrete slots
250
+ * @param pattern - Recurrence pattern
251
+ * @param range - Date range to expand within
252
+ * @param config - Scheduling configuration
253
+ * @returns Array of slots from the recurring pattern
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * const pattern = {
258
+ * frequency: 'weekly',
259
+ * startDate: new Date('2024-01-01'),
260
+ * byWeekday: [1, 3, 5], // Mon, Wed, Fri
261
+ * until: new Date('2024-12-31')
262
+ * };
263
+ * const slots = expandRecurringAvailability(pattern, range);
264
+ * ```
265
+ */
266
+ export function expandRecurringAvailability(pattern, range, config = {}) {
267
+ const occurrences = getOccurrencesBetween(pattern, range.start, range.end);
268
+ const slots = [];
269
+ for (const occurrence of occurrences) {
270
+ const daySlots = generateSlots(occurrence, config);
271
+ slots.push(...daySlots);
272
+ }
273
+ return slots;
274
+ }
275
+ /**
276
+ * Merges adjacent or overlapping bookings
277
+ * @param bookings - Array of bookings to merge
278
+ * @returns Array of merged bookings
279
+ *
280
+ * @example
281
+ * ```ts
282
+ * const bookings = [
283
+ * { start: new Date('2024-01-15T09:00'), end: new Date('2024-01-15T10:00') },
284
+ * { start: new Date('2024-01-15T10:00'), end: new Date('2024-01-15T11:00') }
285
+ * ];
286
+ * const merged = mergeBookings(bookings);
287
+ * // [{ start: 09:00, end: 11:00 }]
288
+ * ```
289
+ */
290
+ export function mergeBookings(bookings) {
291
+ if (bookings.length === 0)
292
+ return [];
293
+ const ranges = mergeDateRanges(bookings);
294
+ return ranges.map(range => ({
295
+ start: range.start,
296
+ end: range.end
297
+ }));
298
+ }
299
+ /**
300
+ * Splits a slot at a specific time
301
+ * @param slot - The slot to split
302
+ * @param at - The time to split at
303
+ * @returns Tuple of two slots, or null if split point is outside slot
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * const slot = { start: new Date('2024-01-15T09:00'), end: new Date('2024-01-15T11:00'), available: true };
308
+ * const [before, after] = splitSlot(slot, new Date('2024-01-15T10:00'));
309
+ * // before: 09:00-10:00, after: 10:00-11:00
310
+ * ```
311
+ */
312
+ export function splitSlot(slot, at) {
313
+ const splitTime = toDate(at);
314
+ if (splitTime <= slot.start || splitTime >= slot.end) {
315
+ return null;
316
+ }
317
+ return [
318
+ {
319
+ start: new Date(slot.start),
320
+ end: new Date(splitTime),
321
+ available: slot.available
322
+ },
323
+ {
324
+ start: new Date(splitTime),
325
+ end: new Date(slot.end),
326
+ available: slot.available
327
+ }
328
+ ];
329
+ }
@@ -0,0 +1,237 @@
1
+ /**
2
+ * @fileoverview Temporal API compatibility layer
3
+ * Provides Temporal-like objects that work with native Date
4
+ * When Temporal ships natively, these become thin wrappers
5
+ */
6
+ /**
7
+ * PlainDate - A date without time or timezone
8
+ * Mirrors Temporal.PlainDate
9
+ */
10
+ export interface PlainDate {
11
+ readonly year: number;
12
+ readonly month: number;
13
+ readonly day: number;
14
+ readonly dayOfWeek: number;
15
+ readonly dayOfYear: number;
16
+ readonly weekOfYear: number;
17
+ readonly daysInMonth: number;
18
+ readonly daysInYear: number;
19
+ readonly monthsInYear: number;
20
+ readonly inLeapYear: boolean;
21
+ toString(): string;
22
+ toJSON(): string;
23
+ equals(other: PlainDate): boolean;
24
+ compare(other: PlainDate): number;
25
+ add(duration: DurationLike): PlainDate;
26
+ subtract(duration: DurationLike): PlainDate;
27
+ until(other: PlainDate): Duration;
28
+ since(other: PlainDate): Duration;
29
+ with(fields: Partial<{
30
+ year: number;
31
+ month: number;
32
+ day: number;
33
+ }>): PlainDate;
34
+ toDate(): Date;
35
+ }
36
+ /**
37
+ * PlainTime - A time without date or timezone
38
+ * Mirrors Temporal.PlainTime
39
+ */
40
+ export interface PlainTime {
41
+ readonly hour: number;
42
+ readonly minute: number;
43
+ readonly second: number;
44
+ readonly millisecond: number;
45
+ toString(): string;
46
+ toJSON(): string;
47
+ equals(other: PlainTime): boolean;
48
+ compare(other: PlainTime): number;
49
+ add(duration: DurationLike): PlainTime;
50
+ subtract(duration: DurationLike): PlainTime;
51
+ with(fields: Partial<{
52
+ hour: number;
53
+ minute: number;
54
+ second: number;
55
+ millisecond: number;
56
+ }>): PlainTime;
57
+ }
58
+ /**
59
+ * PlainDateTime - A date and time without timezone
60
+ * Mirrors Temporal.PlainDateTime
61
+ */
62
+ export interface PlainDateTime {
63
+ readonly year: number;
64
+ readonly month: number;
65
+ readonly day: number;
66
+ readonly hour: number;
67
+ readonly minute: number;
68
+ readonly second: number;
69
+ readonly millisecond: number;
70
+ readonly dayOfWeek: number;
71
+ readonly dayOfYear: number;
72
+ readonly weekOfYear: number;
73
+ toString(): string;
74
+ toJSON(): string;
75
+ equals(other: PlainDateTime): boolean;
76
+ compare(other: PlainDateTime): number;
77
+ add(duration: DurationLike): PlainDateTime;
78
+ subtract(duration: DurationLike): PlainDateTime;
79
+ until(other: PlainDateTime): Duration;
80
+ since(other: PlainDateTime): Duration;
81
+ with(fields: Partial<{
82
+ year: number;
83
+ month: number;
84
+ day: number;
85
+ hour: number;
86
+ minute: number;
87
+ second: number;
88
+ millisecond: number;
89
+ }>): PlainDateTime;
90
+ toPlainDate(): PlainDate;
91
+ toPlainTime(): PlainTime;
92
+ toDate(): Date;
93
+ }
94
+ /**
95
+ * ZonedDateTime - A date and time with timezone
96
+ * Mirrors Temporal.ZonedDateTime
97
+ */
98
+ export interface ZonedDateTime {
99
+ readonly year: number;
100
+ readonly month: number;
101
+ readonly day: number;
102
+ readonly hour: number;
103
+ readonly minute: number;
104
+ readonly second: number;
105
+ readonly millisecond: number;
106
+ readonly timeZone: string;
107
+ readonly offset: string;
108
+ readonly epochMilliseconds: number;
109
+ toString(): string;
110
+ toJSON(): string;
111
+ equals(other: ZonedDateTime): boolean;
112
+ add(duration: DurationLike): ZonedDateTime;
113
+ subtract(duration: DurationLike): ZonedDateTime;
114
+ with(fields: Partial<{
115
+ year: number;
116
+ month: number;
117
+ day: number;
118
+ hour: number;
119
+ minute: number;
120
+ second: number;
121
+ millisecond: number;
122
+ }>): ZonedDateTime;
123
+ toPlainDate(): PlainDate;
124
+ toPlainTime(): PlainTime;
125
+ toPlainDateTime(): PlainDateTime;
126
+ toInstant(): Instant;
127
+ toDate(): Date;
128
+ }
129
+ /**
130
+ * Instant - A point in time (like Unix timestamp)
131
+ * Mirrors Temporal.Instant
132
+ */
133
+ export interface Instant {
134
+ readonly epochMilliseconds: number;
135
+ readonly epochSeconds: number;
136
+ toString(): string;
137
+ toJSON(): string;
138
+ equals(other: Instant): boolean;
139
+ compare(other: Instant): number;
140
+ add(duration: DurationLike): Instant;
141
+ subtract(duration: DurationLike): Instant;
142
+ until(other: Instant): Duration;
143
+ since(other: Instant): Duration;
144
+ toZonedDateTime(timeZone: string): ZonedDateTime;
145
+ toDate(): Date;
146
+ }
147
+ /**
148
+ * Duration - A length of time
149
+ * Mirrors Temporal.Duration
150
+ */
151
+ export interface Duration {
152
+ readonly years: number;
153
+ readonly months: number;
154
+ readonly weeks: number;
155
+ readonly days: number;
156
+ readonly hours: number;
157
+ readonly minutes: number;
158
+ readonly seconds: number;
159
+ readonly milliseconds: number;
160
+ readonly sign: -1 | 0 | 1;
161
+ readonly blank: boolean;
162
+ toString(): string;
163
+ toJSON(): string;
164
+ negated(): Duration;
165
+ abs(): Duration;
166
+ add(other: DurationLike): Duration;
167
+ subtract(other: DurationLike): Duration;
168
+ total(unit: DurationUnit): number;
169
+ }
170
+ export type DurationUnit = 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds';
171
+ export interface DurationLike {
172
+ years?: number;
173
+ months?: number;
174
+ weeks?: number;
175
+ days?: number;
176
+ hours?: number;
177
+ minutes?: number;
178
+ seconds?: number;
179
+ milliseconds?: number;
180
+ }
181
+ /**
182
+ * Create a PlainDate from a Date object or components
183
+ */
184
+ export declare function toPlainDate(date: Date): PlainDate;
185
+ export declare function toPlainDate(year: number, month: number, day: number): PlainDate;
186
+ /**
187
+ * Create a PlainTime from a Date object or components
188
+ */
189
+ export declare function toPlainTime(date: Date): PlainTime;
190
+ export declare function toPlainTime(hour: number, minute?: number, second?: number, millisecond?: number): PlainTime;
191
+ /**
192
+ * Create a PlainDateTime from a Date object or components
193
+ */
194
+ export declare function toPlainDateTime(date: Date): PlainDateTime;
195
+ export declare function toPlainDateTime(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millisecond?: number): PlainDateTime;
196
+ /**
197
+ * Create a ZonedDateTime from a Date object and timezone
198
+ */
199
+ export declare function toZonedDateTime(date: Date, timeZone: string): ZonedDateTime;
200
+ /**
201
+ * Create an Instant from a Date object or epoch milliseconds
202
+ */
203
+ export declare function toInstant(date: Date): Instant;
204
+ export declare function toInstant(epochMs: number): Instant;
205
+ /**
206
+ * Create a Duration from components
207
+ */
208
+ export declare function createDuration(fields?: DurationLike): Duration;
209
+ /**
210
+ * Parse an ISO 8601 duration string
211
+ */
212
+ export declare function parseDuration(str: string): Duration;
213
+ /**
214
+ * Get current instant
215
+ */
216
+ export declare function nowInstant(): Instant;
217
+ /**
218
+ * Get current PlainDateTime in local timezone
219
+ */
220
+ export declare function nowPlainDateTime(): PlainDateTime;
221
+ /**
222
+ * Get current PlainDate in local timezone
223
+ */
224
+ export declare function nowPlainDate(): PlainDate;
225
+ /**
226
+ * Get current PlainTime in local timezone
227
+ */
228
+ export declare function nowPlainTime(): PlainTime;
229
+ /**
230
+ * Get current ZonedDateTime in specified timezone
231
+ */
232
+ export declare function nowZonedDateTime(timeZone: string): ZonedDateTime;
233
+ /**
234
+ * Convert Temporal-like object back to Date
235
+ */
236
+ export declare function fromTemporal(temporal: PlainDate | PlainDateTime | ZonedDateTime | Instant): Date;
237
+ //# sourceMappingURL=temporal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"temporal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