ts-time-utils 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +682 -11
- package/dist/calculate.d.ts +7 -2
- package/dist/calculate.d.ts.map +1 -1
- package/dist/calculate.js +37 -13
- package/dist/calendar.d.ts +103 -0
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +224 -0
- package/dist/compare.d.ts +217 -0
- package/dist/compare.d.ts.map +1 -0
- package/dist/compare.js +417 -0
- package/dist/countdown.d.ts +217 -0
- package/dist/countdown.d.ts.map +1 -0
- package/dist/countdown.js +298 -0
- package/dist/cron.d.ts +82 -0
- package/dist/cron.d.ts.map +1 -0
- package/dist/cron.js +294 -0
- package/dist/dateRange.d.ts +266 -0
- package/dist/dateRange.d.ts.map +1 -0
- package/dist/dateRange.js +433 -0
- package/dist/esm/calculate.d.ts +7 -2
- package/dist/esm/calculate.d.ts.map +1 -1
- package/dist/esm/calculate.js +37 -13
- package/dist/esm/calendar.d.ts +103 -0
- package/dist/esm/calendar.d.ts.map +1 -1
- package/dist/esm/calendar.js +224 -0
- package/dist/esm/compare.d.ts +217 -0
- package/dist/esm/compare.d.ts.map +1 -0
- package/dist/esm/compare.js +417 -0
- package/dist/esm/countdown.d.ts +217 -0
- package/dist/esm/countdown.d.ts.map +1 -0
- package/dist/esm/countdown.js +298 -0
- package/dist/esm/cron.d.ts +82 -0
- package/dist/esm/cron.d.ts.map +1 -0
- package/dist/esm/cron.js +294 -0
- package/dist/esm/dateRange.d.ts +266 -0
- package/dist/esm/dateRange.d.ts.map +1 -0
- package/dist/esm/dateRange.js +433 -0
- package/dist/esm/fiscal.d.ts +195 -0
- package/dist/esm/fiscal.d.ts.map +1 -0
- package/dist/esm/fiscal.js +295 -0
- package/dist/esm/format.d.ts +65 -0
- package/dist/esm/format.d.ts.map +1 -1
- package/dist/esm/format.js +202 -0
- package/dist/esm/index.d.ts +18 -7
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +22 -6
- package/dist/esm/iterate.d.ts +212 -0
- package/dist/esm/iterate.d.ts.map +1 -0
- package/dist/esm/iterate.js +409 -0
- package/dist/esm/naturalLanguage.d.ts +107 -0
- package/dist/esm/naturalLanguage.d.ts.map +1 -0
- package/dist/esm/naturalLanguage.js +344 -0
- package/dist/esm/parse.d.ts +45 -0
- package/dist/esm/parse.d.ts.map +1 -1
- package/dist/esm/parse.js +207 -0
- package/dist/esm/recurrence.d.ts +149 -0
- package/dist/esm/recurrence.d.ts.map +1 -0
- package/dist/esm/recurrence.js +404 -0
- package/dist/esm/timezone.d.ts +52 -0
- package/dist/esm/timezone.d.ts.map +1 -1
- package/dist/esm/timezone.js +171 -0
- package/dist/esm/types.d.ts +21 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/validate.d.ts +51 -0
- package/dist/esm/validate.d.ts.map +1 -1
- package/dist/esm/validate.js +92 -0
- package/dist/esm/workingHours.d.ts +70 -0
- package/dist/esm/workingHours.d.ts.map +1 -1
- package/dist/esm/workingHours.js +161 -0
- package/dist/fiscal.d.ts +195 -0
- package/dist/fiscal.d.ts.map +1 -0
- package/dist/fiscal.js +295 -0
- package/dist/format.d.ts +65 -0
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +202 -0
- package/dist/index.d.ts +18 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -6
- package/dist/iterate.d.ts +212 -0
- package/dist/iterate.d.ts.map +1 -0
- package/dist/iterate.js +409 -0
- package/dist/naturalLanguage.d.ts +107 -0
- package/dist/naturalLanguage.d.ts.map +1 -0
- package/dist/naturalLanguage.js +344 -0
- package/dist/parse.d.ts +45 -0
- package/dist/parse.d.ts.map +1 -1
- package/dist/parse.js +207 -0
- package/dist/recurrence.d.ts +149 -0
- package/dist/recurrence.d.ts.map +1 -0
- package/dist/recurrence.js +404 -0
- package/dist/timezone.d.ts +52 -0
- package/dist/timezone.d.ts.map +1 -1
- package/dist/timezone.js +171 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +51 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +92 -0
- package/dist/workingHours.d.ts +70 -0
- package/dist/workingHours.d.ts.map +1 -1
- package/dist/workingHours.js +161 -0
- package/package.json +59 -12
package/dist/esm/format.js
CHANGED
|
@@ -187,3 +187,205 @@ export function parseDuration(duration) {
|
|
|
187
187
|
}
|
|
188
188
|
return totalMs;
|
|
189
189
|
}
|
|
190
|
+
const MONTH_NAMES = [
|
|
191
|
+
'January', 'February', 'March', 'April', 'May', 'June',
|
|
192
|
+
'July', 'August', 'September', 'October', 'November', 'December'
|
|
193
|
+
];
|
|
194
|
+
const MONTH_NAMES_SHORT = [
|
|
195
|
+
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
196
|
+
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
|
|
197
|
+
];
|
|
198
|
+
const DAY_NAMES = [
|
|
199
|
+
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
|
|
200
|
+
];
|
|
201
|
+
const DAY_NAMES_SHORT = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
202
|
+
/**
|
|
203
|
+
* Format a date using a pattern string
|
|
204
|
+
* @param date - date to format
|
|
205
|
+
* @param pattern - format pattern (e.g., "YYYY-MM-DD", "MMM D, YYYY")
|
|
206
|
+
*
|
|
207
|
+
* Supported tokens:
|
|
208
|
+
* - YYYY: 4-digit year
|
|
209
|
+
* - YY: 2-digit year
|
|
210
|
+
* - MMMM: Full month name (January)
|
|
211
|
+
* - MMM: Short month name (Jan)
|
|
212
|
+
* - MM: Month with leading zero (01-12)
|
|
213
|
+
* - M: Month (1-12)
|
|
214
|
+
* - DDDD: Full day name (Monday)
|
|
215
|
+
* - DDD: Short day name (Mon)
|
|
216
|
+
* - DD: Day with leading zero (01-31)
|
|
217
|
+
* - D: Day (1-31)
|
|
218
|
+
* - HH: Hours 24h with leading zero (00-23)
|
|
219
|
+
* - H: Hours 24h (0-23)
|
|
220
|
+
* - hh: Hours 12h with leading zero (01-12)
|
|
221
|
+
* - h: Hours 12h (1-12)
|
|
222
|
+
* - mm: Minutes with leading zero (00-59)
|
|
223
|
+
* - ss: Seconds with leading zero (00-59)
|
|
224
|
+
* - SSS: Milliseconds (000-999)
|
|
225
|
+
* - A: AM/PM
|
|
226
|
+
* - a: am/pm
|
|
227
|
+
*/
|
|
228
|
+
export function formatDate(date, pattern) {
|
|
229
|
+
const year = date.getFullYear();
|
|
230
|
+
const month = date.getMonth();
|
|
231
|
+
const day = date.getDate();
|
|
232
|
+
const dayOfWeek = date.getDay();
|
|
233
|
+
const hours = date.getHours();
|
|
234
|
+
const minutes = date.getMinutes();
|
|
235
|
+
const seconds = date.getSeconds();
|
|
236
|
+
const milliseconds = date.getMilliseconds();
|
|
237
|
+
const hours12 = hours % 12 || 12;
|
|
238
|
+
const ampm = hours < 12 ? 'AM' : 'PM';
|
|
239
|
+
const pad = (n, len = 2) => String(n).padStart(len, '0');
|
|
240
|
+
// Token mapping - order matters for replacements
|
|
241
|
+
const tokens = [
|
|
242
|
+
[/YYYY/g, String(year)],
|
|
243
|
+
[/YY/g, String(year).slice(-2)],
|
|
244
|
+
[/MMMM/g, MONTH_NAMES[month]],
|
|
245
|
+
[/MMM/g, MONTH_NAMES_SHORT[month]],
|
|
246
|
+
[/MM/g, pad(month + 1)],
|
|
247
|
+
[/\bM\b/g, String(month + 1)], // Word boundary to avoid matching M in other tokens
|
|
248
|
+
[/DDDD/g, DAY_NAMES[dayOfWeek]],
|
|
249
|
+
[/DDD/g, DAY_NAMES_SHORT[dayOfWeek]],
|
|
250
|
+
[/DD/g, pad(day)],
|
|
251
|
+
[/\bD\b/g, String(day)],
|
|
252
|
+
[/HH/g, pad(hours)],
|
|
253
|
+
[/\bH\b/g, String(hours)],
|
|
254
|
+
[/hh/g, pad(hours12)],
|
|
255
|
+
[/\bh\b/g, String(hours12)],
|
|
256
|
+
[/mm/g, pad(minutes)],
|
|
257
|
+
[/ss/g, pad(seconds)],
|
|
258
|
+
[/SSS/g, pad(milliseconds, 3)],
|
|
259
|
+
[/\bA\b/g, ampm],
|
|
260
|
+
[/\ba\b/g, ampm.toLowerCase()],
|
|
261
|
+
];
|
|
262
|
+
let result = pattern;
|
|
263
|
+
for (const [regex, replacement] of tokens) {
|
|
264
|
+
result = result.replace(regex, replacement);
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Format a relative time string (e.g., "in 2 days", "3 hours ago")
|
|
270
|
+
* @param date - target date
|
|
271
|
+
* @param baseDate - base date (default: now)
|
|
272
|
+
*/
|
|
273
|
+
export function formatRelativeTime(date, baseDate = new Date()) {
|
|
274
|
+
const diffMs = date.getTime() - baseDate.getTime();
|
|
275
|
+
const isFuture = diffMs > 0;
|
|
276
|
+
const absDiffMs = Math.abs(diffMs);
|
|
277
|
+
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
|
|
278
|
+
if (absDiffMs < MILLISECONDS_PER_MINUTE) {
|
|
279
|
+
const seconds = Math.round(absDiffMs / MILLISECONDS_PER_SECOND);
|
|
280
|
+
return rtf.format(isFuture ? seconds : -seconds, 'second');
|
|
281
|
+
}
|
|
282
|
+
if (absDiffMs < MILLISECONDS_PER_HOUR) {
|
|
283
|
+
const minutes = Math.round(absDiffMs / MILLISECONDS_PER_MINUTE);
|
|
284
|
+
return rtf.format(isFuture ? minutes : -minutes, 'minute');
|
|
285
|
+
}
|
|
286
|
+
if (absDiffMs < MILLISECONDS_PER_DAY) {
|
|
287
|
+
const hours = Math.round(absDiffMs / MILLISECONDS_PER_HOUR);
|
|
288
|
+
return rtf.format(isFuture ? hours : -hours, 'hour');
|
|
289
|
+
}
|
|
290
|
+
if (absDiffMs < MILLISECONDS_PER_WEEK) {
|
|
291
|
+
const days = Math.round(absDiffMs / MILLISECONDS_PER_DAY);
|
|
292
|
+
return rtf.format(isFuture ? days : -days, 'day');
|
|
293
|
+
}
|
|
294
|
+
if (absDiffMs < MILLISECONDS_PER_MONTH) {
|
|
295
|
+
const weeks = Math.round(absDiffMs / MILLISECONDS_PER_WEEK);
|
|
296
|
+
return rtf.format(isFuture ? weeks : -weeks, 'week');
|
|
297
|
+
}
|
|
298
|
+
if (absDiffMs < MILLISECONDS_PER_YEAR) {
|
|
299
|
+
const months = Math.round(absDiffMs / MILLISECONDS_PER_MONTH);
|
|
300
|
+
return rtf.format(isFuture ? months : -months, 'month');
|
|
301
|
+
}
|
|
302
|
+
const years = Math.round(absDiffMs / MILLISECONDS_PER_YEAR);
|
|
303
|
+
return rtf.format(isFuture ? years : -years, 'year');
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Format a date range (e.g., "Jan 5 - Jan 10, 2025")
|
|
307
|
+
* @param start - start date
|
|
308
|
+
* @param end - end date
|
|
309
|
+
* @param options - formatting options
|
|
310
|
+
*/
|
|
311
|
+
export function formatDateRange(start, end, options = {}) {
|
|
312
|
+
const { separator = ' - ', includeTime = false, format = 'medium' } = options;
|
|
313
|
+
const sameYear = start.getFullYear() === end.getFullYear();
|
|
314
|
+
const sameMonth = sameYear && start.getMonth() === end.getMonth();
|
|
315
|
+
const sameDay = sameMonth && start.getDate() === end.getDate();
|
|
316
|
+
const formatOptions = {
|
|
317
|
+
month: format === 'short' ? 'short' : format === 'long' ? 'long' : 'short',
|
|
318
|
+
day: 'numeric',
|
|
319
|
+
};
|
|
320
|
+
if (!sameYear || format === 'long') {
|
|
321
|
+
formatOptions.year = 'numeric';
|
|
322
|
+
}
|
|
323
|
+
if (includeTime) {
|
|
324
|
+
formatOptions.hour = 'numeric';
|
|
325
|
+
formatOptions.minute = '2-digit';
|
|
326
|
+
}
|
|
327
|
+
if (sameDay && !includeTime) {
|
|
328
|
+
return start.toLocaleDateString('en-US', { ...formatOptions, year: 'numeric' });
|
|
329
|
+
}
|
|
330
|
+
const startStr = start.toLocaleDateString('en-US', formatOptions);
|
|
331
|
+
const endStr = end.toLocaleDateString('en-US', { ...formatOptions, year: 'numeric' });
|
|
332
|
+
return `${startStr}${separator}${endStr}`;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Format a number as an ordinal (1st, 2nd, 3rd, etc.)
|
|
336
|
+
* @param n - number to format
|
|
337
|
+
*/
|
|
338
|
+
export function formatOrdinal(n) {
|
|
339
|
+
const suffixes = ['th', 'st', 'nd', 'rd'];
|
|
340
|
+
const v = n % 100;
|
|
341
|
+
return n + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Format a day of month as an ordinal (1st, 2nd, 3rd, etc.)
|
|
345
|
+
* @param date - date to format
|
|
346
|
+
*/
|
|
347
|
+
export function formatDayOrdinal(date) {
|
|
348
|
+
return formatOrdinal(date.getDate());
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Format a duration in a compact form (e.g., "02:30:45")
|
|
352
|
+
* @param ms - milliseconds
|
|
353
|
+
* @param showHours - always show hours even if 0
|
|
354
|
+
*/
|
|
355
|
+
export function formatDurationCompact(ms, showHours = true) {
|
|
356
|
+
const hours = Math.floor(ms / MILLISECONDS_PER_HOUR);
|
|
357
|
+
const minutes = Math.floor((ms % MILLISECONDS_PER_HOUR) / MILLISECONDS_PER_MINUTE);
|
|
358
|
+
const seconds = Math.floor((ms % MILLISECONDS_PER_MINUTE) / MILLISECONDS_PER_SECOND);
|
|
359
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
360
|
+
if (showHours || hours > 0) {
|
|
361
|
+
return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
|
|
362
|
+
}
|
|
363
|
+
return `${pad(minutes)}:${pad(seconds)}`;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Format a date/time for display in a calendar
|
|
367
|
+
* @param date - date to format
|
|
368
|
+
*/
|
|
369
|
+
export function formatCalendarDate(date) {
|
|
370
|
+
const now = new Date();
|
|
371
|
+
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
372
|
+
const dateOnly = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
373
|
+
const diffDays = Math.round((dateOnly.getTime() - today.getTime()) / MILLISECONDS_PER_DAY);
|
|
374
|
+
if (diffDays === 0)
|
|
375
|
+
return 'Today';
|
|
376
|
+
if (diffDays === -1)
|
|
377
|
+
return 'Yesterday';
|
|
378
|
+
if (diffDays === 1)
|
|
379
|
+
return 'Tomorrow';
|
|
380
|
+
if (diffDays > 1 && diffDays < 7) {
|
|
381
|
+
return DAY_NAMES[date.getDay()];
|
|
382
|
+
}
|
|
383
|
+
if (diffDays >= -6 && diffDays < 0) {
|
|
384
|
+
return `Last ${DAY_NAMES[date.getDay()]}`;
|
|
385
|
+
}
|
|
386
|
+
// Same year, show month and day
|
|
387
|
+
if (date.getFullYear() === now.getFullYear()) {
|
|
388
|
+
return formatDate(date, 'MMM D');
|
|
389
|
+
}
|
|
390
|
+
return formatDate(date, 'MMM D, YYYY');
|
|
391
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,20 +2,31 @@
|
|
|
2
2
|
* @fileoverview Main entry point for ts-time-utils library
|
|
3
3
|
* Re-exports all functions from individual modules for convenience
|
|
4
4
|
*/
|
|
5
|
-
export { formatDuration, timeAgo, formatTime, parseDuration } from './format.js';
|
|
5
|
+
export { formatDuration, timeAgo, formatTime, parseDuration, formatDate, formatDateRange, formatOrdinal, formatDayOrdinal, formatDurationCompact, formatCalendarDate } from './format.js';
|
|
6
6
|
export { differenceInUnits, addTime, subtractTime, startOf, endOf, isBetween, businessDaysBetween } from './calculate.js';
|
|
7
|
-
export { isValidDate, isLeapYear, isPast, isFuture, isToday, isYesterday, isTomorrow, isSameDay, isWeekend, isWeekday, isValidTimeString, isValidISOString } from './validate.js';
|
|
7
|
+
export { isValidDate, isLeapYear, isPast, isFuture, isToday, isYesterday, isTomorrow, isSameDay, isSameWeek, isSameMonth, isSameYear, isThisWeek, isThisMonth, isThisYear, isWeekend, isWeekday, isBusinessDay, isInLastNDays, isInNextNDays, isValidTimeString, isValidISOString } from './validate.js';
|
|
8
8
|
export { calculateAge, getAgeInUnits, getLifeStage, getNextBirthday, getDaysUntilBirthday, isBirthday } from './age.js';
|
|
9
|
-
export { getWeekNumber, getWeekOfMonth, getQuarter, getDayOfYear, getWeeksInYear, getDaysInMonth, getDaysInYear, getEaster, getMonthsInYear, getDaysInMonthArray, getWeekdaysInMonth, getFirstDayOfMonth, getLastDayOfMonth, getFirstDayOfYear, getLastDayOfYear } from './calendar.js';
|
|
10
|
-
export {
|
|
9
|
+
export { getWeekNumber, getWeekOfMonth, getQuarter, getDayOfYear, getWeeksInYear, getDaysInMonth, getDaysInYear, getEaster, getMonthsInYear, getDaysInMonthArray, getWeekdaysInMonth, getFirstDayOfMonth, getLastDayOfMonth, getFirstDayOfYear, getLastDayOfYear, getNthDayOfMonth, getNewYearsDay, getMLKDay, getPresidentsDay, getMemorialDay, getIndependenceDay, getLaborDay, getColumbusDay, getVeteransDay, getThanksgivingDay, getChristmasDay, getGoodFriday, getUSHolidays, isUSHoliday, getUSHolidayName, getStartOfWeek, getEndOfWeek, getWeeksInMonth } from './calendar.js';
|
|
10
|
+
export type { USHoliday } from './calendar.js';
|
|
11
|
+
export { parseDate, parseRelativeDate, parseTimeAgo, parseCustomFormat, parseManyFormats, parseISO8601Duration, parseISO8601DurationToMs, parseTime, guessDateFormat, parseAutoFormat, parseRangeEndpoint } from './parse.js';
|
|
11
12
|
export { sleep, timeout, debounce, throttle, retry, createStopwatch, measureTime, measureAsync, benchmark, Stopwatch } from './performance.js';
|
|
12
13
|
export { createInterval, isValidInterval, intervalDuration, intervalContains, intervalsOverlap, intervalIntersection, mergeIntervals, subtractInterval, splitIntervalByDay, totalIntervalCoverage, normalizeIntervals } from './interval.js';
|
|
13
|
-
export { getTimezoneOffset, formatInTimeZone, getZonedTime, convertDateToZone, isValidTimeZone, COMMON_TIMEZONES, getLocalOffset, compareZoneOffsets, reinterpretAsZone } from './timezone.js';
|
|
14
|
-
export { DEFAULT_WORKING_HOURS, isWorkingDay, isWorkingTime, nextWorkingTime, workingTimeBetween, addWorkingHours } from './workingHours.js';
|
|
14
|
+
export { getTimezoneOffset, formatInTimeZone, getZonedTime, convertDateToZone, isValidTimeZone, COMMON_TIMEZONES, getLocalOffset, compareZoneOffsets, reinterpretAsZone, isDST, getNextDSTTransition, findCommonWorkingHours, getTimezoneAbbreviation, convertBetweenZones, getTimezoneDifferenceHours, isSameTimezone } from './timezone.js';
|
|
15
|
+
export { DEFAULT_WORKING_HOURS, isWorkingDay, isWorkingTime, nextWorkingTime, workingTimeBetween, addWorkingHours, addWorkingDays, subtractWorkingDays, getNextWorkingDay, getPreviousWorkingDay, getWorkingDaysInMonth, getWorkingDaysInMonthArray, workingDaysBetween, isBreakTime, getWorkDayStart, getWorkDayEnd, getWorkingHoursPerDay } from './workingHours.js';
|
|
15
16
|
export { today, yesterday, tomorrow, lastNDays, nextNDays, thisWeek, lastWeek, nextWeek, thisMonth, lastMonth, nextMonth, thisYear, lastYear, nextYear, rollingWindowDays, quarterRange, lastQuarter, nextQuarter, RANGE_PRESETS } from './rangePresets.js';
|
|
16
17
|
export { Duration, createDuration, isValidDuration, parseDurationString, formatDurationString, maxDuration, minDuration, sumDurations, averageDuration } from './duration.js';
|
|
17
18
|
export { serializeDate, deserializeDate, createDateReviver, createDateReplacer, parseISOString, toEpochTimestamp, fromEpochTimestamp, createEpochTimestamp, toDateObject, fromDateObject, isValidISODateString, isValidEpochTimestamp, cloneDate, datesEqual, now, parseJSONWithDates, stringifyWithDates } from './serialize.js';
|
|
18
19
|
export { registerLocale, getLocaleConfig, getSupportedLocales, formatRelativeTime, formatDateLocale, formatTimeLocale, formatDateTimeLocale, getMonthNames, getDayNames, getFirstDayOfWeek, isLocaleSupported, getBestMatchingLocale, detectLocale, convertRelativeTime, detectLocaleFromRelativeTime, convertFormatPattern, convertFormattedDate, convertRelativeTimeArray, compareLocaleFormats } from './locale.js';
|
|
20
|
+
export { createRecurrence, getNextOccurrence, getOccurrencesBetween, isRecurrenceDate, isValidRecurrenceRule, recurrenceToString } from './recurrence.js';
|
|
21
|
+
export { createCountdown, getRemainingTime, formatCountdown, isExpired, getProgressPercentage, getTimeUntil, createDeadline, type Countdown, type RemainingTime, type CountdownOptions } from './countdown.js';
|
|
22
|
+
export { dateRangeOverlap, hasOverlappingRanges, mergeDateRanges, findGaps, splitRange, containsDate, getIntersection, getUnion, subtractRange, getRangeDuration, expandRange, shrinkRange, rangeContains, sortRanges } from './dateRange.js';
|
|
23
|
+
export { parseNaturalDate, parseRelativePhrase, extractDatesFromText, suggestDateFromContext, type NaturalParseOptions, type ExtractedDate } from './naturalLanguage.js';
|
|
19
24
|
export { MILLISECONDS_PER_SECOND, MILLISECONDS_PER_MINUTE, MILLISECONDS_PER_HOUR, MILLISECONDS_PER_DAY, MILLISECONDS_PER_WEEK, MILLISECONDS_PER_MONTH, MILLISECONDS_PER_YEAR, SECONDS_PER_MINUTE, SECONDS_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_WEEK, type TimeUnit, type FormatOptions } from './constants.js';
|
|
20
|
-
export type { DateInput, DateRange, ParseOptions, WorkingHoursConfig, AgeResult, ZonedTime, Interval, BenchmarkResult, RecurrencePattern, LocaleFormatOptions, BusinessConfig, DateValidator, DateTransformer, TimeUtilsError, ParseError, ValidationError, DurationUnit, DurationInput, DurationComparison, SerializationOptions, DateObject, EpochTimestamp, SupportedLocale, LocaleConfig, RelativeTimeOptions, RelativeTimeUnit } from './types.js';
|
|
25
|
+
export type { DateInput, DateRange, ParseOptions, WorkingHoursConfig, AgeResult, ZonedTime, Interval, BenchmarkResult, RecurrencePattern, RecurrenceRule, RecurrenceFrequency, LocaleFormatOptions, BusinessConfig, DateValidator, DateTransformer, TimeUtilsError, ParseError, ValidationError, DurationUnit, DurationInput, DurationComparison, SerializationOptions, DateObject, EpochTimestamp, SupportedLocale, LocaleConfig, RelativeTimeOptions, RelativeTimeUnit } from './types.js';
|
|
26
|
+
export { parseCronExpression, parseCronField, matchesCron, getNextCronDate, getNextCronDates, getPreviousCronDate, isValidCron, describeCron, CRON_PRESETS } from './cron.js';
|
|
27
|
+
export type { CronParts, ParsedCronField } from './cron.js';
|
|
28
|
+
export { getFiscalYear, getFiscalQuarter, getFiscalYearStart, getFiscalYearEnd, getFiscalQuarterStart, getFiscalQuarterEnd, isSameFiscalYear, isSameFiscalQuarter, getFiscalMonth, getDaysRemainingInFiscalYear, getDaysElapsedInFiscalYear, getFiscalYearProgress, getFiscalWeek, formatFiscalYear, formatFiscalQuarter, getFiscalPeriodInfo, FISCAL_PRESETS } from './fiscal.js';
|
|
29
|
+
export type { FiscalConfig } from './fiscal.js';
|
|
30
|
+
export { compareDates, compareDatesDesc, sortDates, minDate, maxDate, dateExtent, uniqueDates, closestDate, closestFutureDate, closestPastDate, clampDate, isDateInRange, filterDatesInRange, groupDates, groupDatesByYear, groupDatesByMonth, groupDatesByDay, groupDatesByDayOfWeek, medianDate, averageDate, roundDate, snapDate, isChronological, dateSpan, partitionDates, nthDate } from './compare.js';
|
|
31
|
+
export { eachDay, eachWeekday, eachWeekend, eachWeek, eachMonth, eachQuarter, eachYear, eachHour, eachMinute, eachDayOfWeek, eachInterval, countDays, countWeekdays, countWeekendDays, countWeeks, countMonths, iterateDates, iterateDays, iterateWeekdays, iterateMonths, filterDays, eachMonthEnd, eachNthDayOfMonth } from './iterate.js';
|
|
21
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,cAAc,EACd,OAAO,EACP,UAAU,EACV,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,cAAc,EACd,OAAO,EACP,UAAU,EACV,aAAa,EACb,UAAU,EACV,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,iBAAiB,EACjB,OAAO,EACP,YAAY,EACZ,OAAO,EACP,KAAK,EACL,SAAS,EACT,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,aAAa,EACb,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,eAAe,EACf,oBAAoB,EACpB,UAAU,EACX,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,aAAa,EACb,cAAc,EACd,UAAU,EACV,YAAY,EACZ,cAAc,EACd,cAAc,EACd,aAAa,EACb,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,eAAe,EAChB,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,SAAS,EAAE,MAAM,eAA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Aa,CAAC;AAErB,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,OAAO,EACP,OAAO,EACP,UAAU,EACV,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,aAAa,EACb,kBAAkB,EAClB,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,UAAU,EACV,WAAW,EACX,SAAS,EACT,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,cAAc,EACd,OAAO,EACR,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,OAAO,EACP,WAAW,EACX,WAAW,EACX,QAAQ,EACR,SAAS,EACT,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,aAAa,EACb,YAAY,EACZ,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,eAAe,EACf,aAAa,EACb,UAAU,EACV,YAAY,EACZ,iBAAiB,EAClB,MAAM,cAAc,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -3,25 +3,25 @@
|
|
|
3
3
|
* Re-exports all functions from individual modules for convenience
|
|
4
4
|
*/
|
|
5
5
|
// Format utilities
|
|
6
|
-
export { formatDuration, timeAgo, formatTime, parseDuration } from './format.js';
|
|
6
|
+
export { formatDuration, timeAgo, formatTime, parseDuration, formatDate, formatDateRange, formatOrdinal, formatDayOrdinal, formatDurationCompact, formatCalendarDate } from './format.js';
|
|
7
7
|
// Calculation utilities
|
|
8
8
|
export { differenceInUnits, addTime, subtractTime, startOf, endOf, isBetween, businessDaysBetween } from './calculate.js';
|
|
9
9
|
// Validation utilities
|
|
10
|
-
export { isValidDate, isLeapYear, isPast, isFuture, isToday, isYesterday, isTomorrow, isSameDay, isWeekend, isWeekday, isValidTimeString, isValidISOString } from './validate.js';
|
|
10
|
+
export { isValidDate, isLeapYear, isPast, isFuture, isToday, isYesterday, isTomorrow, isSameDay, isSameWeek, isSameMonth, isSameYear, isThisWeek, isThisMonth, isThisYear, isWeekend, isWeekday, isBusinessDay, isInLastNDays, isInNextNDays, isValidTimeString, isValidISOString } from './validate.js';
|
|
11
11
|
// Age utilities
|
|
12
12
|
export { calculateAge, getAgeInUnits, getLifeStage, getNextBirthday, getDaysUntilBirthday, isBirthday } from './age.js';
|
|
13
13
|
// Calendar utilities
|
|
14
|
-
export { getWeekNumber, getWeekOfMonth, getQuarter, getDayOfYear, getWeeksInYear, getDaysInMonth, getDaysInYear, getEaster, getMonthsInYear, getDaysInMonthArray, getWeekdaysInMonth, getFirstDayOfMonth, getLastDayOfMonth, getFirstDayOfYear, getLastDayOfYear } from './calendar.js';
|
|
14
|
+
export { getWeekNumber, getWeekOfMonth, getQuarter, getDayOfYear, getWeeksInYear, getDaysInMonth, getDaysInYear, getEaster, getMonthsInYear, getDaysInMonthArray, getWeekdaysInMonth, getFirstDayOfMonth, getLastDayOfMonth, getFirstDayOfYear, getLastDayOfYear, getNthDayOfMonth, getNewYearsDay, getMLKDay, getPresidentsDay, getMemorialDay, getIndependenceDay, getLaborDay, getColumbusDay, getVeteransDay, getThanksgivingDay, getChristmasDay, getGoodFriday, getUSHolidays, isUSHoliday, getUSHolidayName, getStartOfWeek, getEndOfWeek, getWeeksInMonth } from './calendar.js';
|
|
15
15
|
// Parse utilities
|
|
16
|
-
export { parseDate, parseRelativeDate, parseTimeAgo, parseCustomFormat, parseManyFormats } from './parse.js';
|
|
16
|
+
export { parseDate, parseRelativeDate, parseTimeAgo, parseCustomFormat, parseManyFormats, parseISO8601Duration, parseISO8601DurationToMs, parseTime, guessDateFormat, parseAutoFormat, parseRangeEndpoint } from './parse.js';
|
|
17
17
|
// Performance utilities
|
|
18
18
|
export { sleep, timeout, debounce, throttle, retry, createStopwatch, measureTime, measureAsync, benchmark, Stopwatch } from './performance.js';
|
|
19
19
|
// Interval utilities
|
|
20
20
|
export { createInterval, isValidInterval, intervalDuration, intervalContains, intervalsOverlap, intervalIntersection, mergeIntervals, subtractInterval, splitIntervalByDay, totalIntervalCoverage, normalizeIntervals } from './interval.js';
|
|
21
21
|
// Timezone utilities
|
|
22
|
-
export { getTimezoneOffset, formatInTimeZone, getZonedTime, convertDateToZone, isValidTimeZone, COMMON_TIMEZONES, getLocalOffset, compareZoneOffsets, reinterpretAsZone } from './timezone.js';
|
|
22
|
+
export { getTimezoneOffset, formatInTimeZone, getZonedTime, convertDateToZone, isValidTimeZone, COMMON_TIMEZONES, getLocalOffset, compareZoneOffsets, reinterpretAsZone, isDST, getNextDSTTransition, findCommonWorkingHours, getTimezoneAbbreviation, convertBetweenZones, getTimezoneDifferenceHours, isSameTimezone } from './timezone.js';
|
|
23
23
|
// Working hours utilities
|
|
24
|
-
export { DEFAULT_WORKING_HOURS, isWorkingDay, isWorkingTime, nextWorkingTime, workingTimeBetween, addWorkingHours } from './workingHours.js';
|
|
24
|
+
export { DEFAULT_WORKING_HOURS, isWorkingDay, isWorkingTime, nextWorkingTime, workingTimeBetween, addWorkingHours, addWorkingDays, subtractWorkingDays, getNextWorkingDay, getPreviousWorkingDay, getWorkingDaysInMonth, getWorkingDaysInMonthArray, workingDaysBetween, isBreakTime, getWorkDayStart, getWorkDayEnd, getWorkingHoursPerDay } from './workingHours.js';
|
|
25
25
|
// Range preset utilities
|
|
26
26
|
export { today, yesterday, tomorrow, lastNDays, nextNDays, thisWeek, lastWeek, nextWeek, thisMonth, lastMonth, nextMonth, thisYear, lastYear, nextYear, rollingWindowDays, quarterRange, lastQuarter, nextQuarter, RANGE_PRESETS } from './rangePresets.js';
|
|
27
27
|
// Duration utilities
|
|
@@ -32,5 +32,21 @@ export { serializeDate, deserializeDate, createDateReviver, createDateReplacer,
|
|
|
32
32
|
export { registerLocale, getLocaleConfig, getSupportedLocales, formatRelativeTime, formatDateLocale, formatTimeLocale, formatDateTimeLocale, getMonthNames, getDayNames, getFirstDayOfWeek, isLocaleSupported, getBestMatchingLocale, detectLocale,
|
|
33
33
|
// Conversion utilities
|
|
34
34
|
convertRelativeTime, detectLocaleFromRelativeTime, convertFormatPattern, convertFormattedDate, convertRelativeTimeArray, compareLocaleFormats } from './locale.js';
|
|
35
|
+
// Recurrence utilities
|
|
36
|
+
export { createRecurrence, getNextOccurrence, getOccurrencesBetween, isRecurrenceDate, isValidRecurrenceRule, recurrenceToString } from './recurrence.js';
|
|
37
|
+
// Countdown utilities
|
|
38
|
+
export { createCountdown, getRemainingTime, formatCountdown, isExpired, getProgressPercentage, getTimeUntil, createDeadline } from './countdown.js';
|
|
39
|
+
// Date range utilities
|
|
40
|
+
export { dateRangeOverlap, hasOverlappingRanges, mergeDateRanges, findGaps, splitRange, containsDate, getIntersection, getUnion, subtractRange, getRangeDuration, expandRange, shrinkRange, rangeContains, sortRanges } from './dateRange.js';
|
|
41
|
+
// Natural language parsing utilities
|
|
42
|
+
export { parseNaturalDate, parseRelativePhrase, extractDatesFromText, suggestDateFromContext } from './naturalLanguage.js';
|
|
35
43
|
// Constants and types
|
|
36
44
|
export { MILLISECONDS_PER_SECOND, MILLISECONDS_PER_MINUTE, MILLISECONDS_PER_HOUR, MILLISECONDS_PER_DAY, MILLISECONDS_PER_WEEK, MILLISECONDS_PER_MONTH, MILLISECONDS_PER_YEAR, SECONDS_PER_MINUTE, SECONDS_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_WEEK } from './constants.js';
|
|
45
|
+
// Cron expression utilities
|
|
46
|
+
export { parseCronExpression, parseCronField, matchesCron, getNextCronDate, getNextCronDates, getPreviousCronDate, isValidCron, describeCron, CRON_PRESETS } from './cron.js';
|
|
47
|
+
// Fiscal year utilities
|
|
48
|
+
export { getFiscalYear, getFiscalQuarter, getFiscalYearStart, getFiscalYearEnd, getFiscalQuarterStart, getFiscalQuarterEnd, isSameFiscalYear, isSameFiscalQuarter, getFiscalMonth, getDaysRemainingInFiscalYear, getDaysElapsedInFiscalYear, getFiscalYearProgress, getFiscalWeek, formatFiscalYear, formatFiscalQuarter, getFiscalPeriodInfo, FISCAL_PRESETS } from './fiscal.js';
|
|
49
|
+
// Date comparison and sorting utilities
|
|
50
|
+
export { compareDates, compareDatesDesc, sortDates, minDate, maxDate, dateExtent, uniqueDates, closestDate, closestFutureDate, closestPastDate, clampDate, isDateInRange, filterDatesInRange, groupDates, groupDatesByYear, groupDatesByMonth, groupDatesByDay, groupDatesByDayOfWeek, medianDate, averageDate, roundDate, snapDate, isChronological, dateSpan, partitionDates, nthDate } from './compare.js';
|
|
51
|
+
// Date iteration utilities
|
|
52
|
+
export { eachDay, eachWeekday, eachWeekend, eachWeek, eachMonth, eachQuarter, eachYear, eachHour, eachMinute, eachDayOfWeek, eachInterval, countDays, countWeekdays, countWeekendDays, countWeeks, countMonths, iterateDates, iterateDays, iterateWeekdays, iterateMonths, filterDays, eachMonthEnd, eachNthDayOfMonth } from './iterate.js';
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Date iteration utilities for generating date sequences
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generate an array of dates for each day in a range
|
|
6
|
+
* @param start - Start date (inclusive)
|
|
7
|
+
* @param end - End date (inclusive)
|
|
8
|
+
* @returns Array of dates, one per day
|
|
9
|
+
* @example
|
|
10
|
+
* eachDay(new Date('2024-01-01'), new Date('2024-01-05'))
|
|
11
|
+
* // [Jan 1, Jan 2, Jan 3, Jan 4, Jan 5]
|
|
12
|
+
*/
|
|
13
|
+
export declare function eachDay(start: Date, end: Date): Date[];
|
|
14
|
+
/**
|
|
15
|
+
* Generate an array of dates for each weekday (Mon-Fri) in a range
|
|
16
|
+
* @param start - Start date (inclusive)
|
|
17
|
+
* @param end - End date (inclusive)
|
|
18
|
+
* @returns Array of weekday dates
|
|
19
|
+
* @example
|
|
20
|
+
* eachWeekday(new Date('2024-01-01'), new Date('2024-01-07'))
|
|
21
|
+
* // [Jan 1 (Mon), Jan 2 (Tue), Jan 3 (Wed), Jan 4 (Thu), Jan 5 (Fri)]
|
|
22
|
+
*/
|
|
23
|
+
export declare function eachWeekday(start: Date, end: Date): Date[];
|
|
24
|
+
/**
|
|
25
|
+
* Generate an array of dates for each weekend day (Sat-Sun) in a range
|
|
26
|
+
* @param start - Start date (inclusive)
|
|
27
|
+
* @param end - End date (inclusive)
|
|
28
|
+
* @returns Array of weekend dates
|
|
29
|
+
*/
|
|
30
|
+
export declare function eachWeekend(start: Date, end: Date): Date[];
|
|
31
|
+
/**
|
|
32
|
+
* Generate an array of dates for each week start in a range
|
|
33
|
+
* @param start - Start date (inclusive)
|
|
34
|
+
* @param end - End date (inclusive)
|
|
35
|
+
* @param weekStartsOn - Day week starts on (0=Sunday, 1=Monday, default: 0)
|
|
36
|
+
* @returns Array of week start dates
|
|
37
|
+
* @example
|
|
38
|
+
* eachWeek(new Date('2024-01-01'), new Date('2024-01-31'))
|
|
39
|
+
* // [Jan 7, Jan 14, Jan 21, Jan 28] (Sundays)
|
|
40
|
+
*/
|
|
41
|
+
export declare function eachWeek(start: Date, end: Date, weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6): Date[];
|
|
42
|
+
/**
|
|
43
|
+
* Generate an array of dates for the first day of each month in a range
|
|
44
|
+
* @param start - Start date (inclusive)
|
|
45
|
+
* @param end - End date (inclusive)
|
|
46
|
+
* @returns Array of first-of-month dates
|
|
47
|
+
* @example
|
|
48
|
+
* eachMonth(new Date('2024-01-15'), new Date('2024-04-15'))
|
|
49
|
+
* // [Feb 1, Mar 1, Apr 1]
|
|
50
|
+
*/
|
|
51
|
+
export declare function eachMonth(start: Date, end: Date): Date[];
|
|
52
|
+
/**
|
|
53
|
+
* Generate an array of dates for the first day of each quarter in a range
|
|
54
|
+
* @param start - Start date (inclusive)
|
|
55
|
+
* @param end - End date (inclusive)
|
|
56
|
+
* @returns Array of quarter start dates
|
|
57
|
+
*/
|
|
58
|
+
export declare function eachQuarter(start: Date, end: Date): Date[];
|
|
59
|
+
/**
|
|
60
|
+
* Generate an array of dates for January 1st of each year in a range
|
|
61
|
+
* @param start - Start date (inclusive)
|
|
62
|
+
* @param end - End date (inclusive)
|
|
63
|
+
* @returns Array of year start dates
|
|
64
|
+
*/
|
|
65
|
+
export declare function eachYear(start: Date, end: Date): Date[];
|
|
66
|
+
/**
|
|
67
|
+
* Generate an array of dates at regular hour intervals
|
|
68
|
+
* @param start - Start date/time (inclusive)
|
|
69
|
+
* @param end - End date/time (inclusive)
|
|
70
|
+
* @param step - Hour interval (default: 1)
|
|
71
|
+
* @returns Array of dates at each interval
|
|
72
|
+
* @example
|
|
73
|
+
* eachHour(new Date('2024-01-01T09:00'), new Date('2024-01-01T12:00'))
|
|
74
|
+
* // [9:00, 10:00, 11:00, 12:00]
|
|
75
|
+
*/
|
|
76
|
+
export declare function eachHour(start: Date, end: Date, step?: number): Date[];
|
|
77
|
+
/**
|
|
78
|
+
* Generate an array of dates at regular minute intervals
|
|
79
|
+
* @param start - Start date/time (inclusive)
|
|
80
|
+
* @param end - End date/time (inclusive)
|
|
81
|
+
* @param step - Minute interval (default: 1)
|
|
82
|
+
* @returns Array of dates at each interval
|
|
83
|
+
* @example
|
|
84
|
+
* eachMinute(new Date('2024-01-01T09:00'), new Date('2024-01-01T09:05'))
|
|
85
|
+
* // [9:00, 9:01, 9:02, 9:03, 9:04, 9:05]
|
|
86
|
+
*/
|
|
87
|
+
export declare function eachMinute(start: Date, end: Date, step?: number): Date[];
|
|
88
|
+
/**
|
|
89
|
+
* Generate an array of dates for a specific day of the week in a range
|
|
90
|
+
* @param start - Start date (inclusive)
|
|
91
|
+
* @param end - End date (inclusive)
|
|
92
|
+
* @param dayOfWeek - Day of week (0=Sunday, 1=Monday, ..., 6=Saturday)
|
|
93
|
+
* @returns Array of dates for that day of week
|
|
94
|
+
* @example
|
|
95
|
+
* eachDayOfWeek(new Date('2024-01-01'), new Date('2024-01-31'), 1)
|
|
96
|
+
* // All Mondays in January 2024
|
|
97
|
+
*/
|
|
98
|
+
export declare function eachDayOfWeek(start: Date, end: Date, dayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6): Date[];
|
|
99
|
+
/**
|
|
100
|
+
* Generate dates at a custom interval
|
|
101
|
+
* @param start - Start date (inclusive)
|
|
102
|
+
* @param end - End date (inclusive)
|
|
103
|
+
* @param interval - Interval configuration
|
|
104
|
+
* @returns Array of dates at each interval
|
|
105
|
+
* @example
|
|
106
|
+
* eachInterval(start, end, { days: 3 }) // Every 3 days
|
|
107
|
+
* eachInterval(start, end, { weeks: 2 }) // Every 2 weeks
|
|
108
|
+
* eachInterval(start, end, { hours: 6 }) // Every 6 hours
|
|
109
|
+
*/
|
|
110
|
+
export declare function eachInterval(start: Date, end: Date, interval: {
|
|
111
|
+
years?: number;
|
|
112
|
+
months?: number;
|
|
113
|
+
weeks?: number;
|
|
114
|
+
days?: number;
|
|
115
|
+
hours?: number;
|
|
116
|
+
minutes?: number;
|
|
117
|
+
seconds?: number;
|
|
118
|
+
}): Date[];
|
|
119
|
+
/**
|
|
120
|
+
* Count the number of days in a range
|
|
121
|
+
* @param start - Start date (inclusive)
|
|
122
|
+
* @param end - End date (inclusive)
|
|
123
|
+
* @returns Number of days
|
|
124
|
+
*/
|
|
125
|
+
export declare function countDays(start: Date, end: Date): number;
|
|
126
|
+
/**
|
|
127
|
+
* Count the number of weekdays in a range
|
|
128
|
+
* @param start - Start date (inclusive)
|
|
129
|
+
* @param end - End date (inclusive)
|
|
130
|
+
* @returns Number of weekdays
|
|
131
|
+
*/
|
|
132
|
+
export declare function countWeekdays(start: Date, end: Date): number;
|
|
133
|
+
/**
|
|
134
|
+
* Count the number of weekend days in a range
|
|
135
|
+
* @param start - Start date (inclusive)
|
|
136
|
+
* @param end - End date (inclusive)
|
|
137
|
+
* @returns Number of weekend days
|
|
138
|
+
*/
|
|
139
|
+
export declare function countWeekendDays(start: Date, end: Date): number;
|
|
140
|
+
/**
|
|
141
|
+
* Count the number of weeks (complete or partial) in a range
|
|
142
|
+
* @param start - Start date (inclusive)
|
|
143
|
+
* @param end - End date (inclusive)
|
|
144
|
+
* @returns Number of weeks
|
|
145
|
+
*/
|
|
146
|
+
export declare function countWeeks(start: Date, end: Date): number;
|
|
147
|
+
/**
|
|
148
|
+
* Count the number of months in a range
|
|
149
|
+
* @param start - Start date (inclusive)
|
|
150
|
+
* @param end - End date (inclusive)
|
|
151
|
+
* @returns Number of months (partial months count as 1)
|
|
152
|
+
*/
|
|
153
|
+
export declare function countMonths(start: Date, end: Date): number;
|
|
154
|
+
/**
|
|
155
|
+
* Iterator for lazy date generation (memory efficient for large ranges)
|
|
156
|
+
* @param start - Start date (inclusive)
|
|
157
|
+
* @param end - End date (inclusive)
|
|
158
|
+
* @param step - Step function to advance the date
|
|
159
|
+
* @yields Date objects
|
|
160
|
+
*/
|
|
161
|
+
export declare function iterateDates(start: Date, end: Date, step?: (current: Date) => void): Generator<Date, void, unknown>;
|
|
162
|
+
/**
|
|
163
|
+
* Create a lazy day iterator
|
|
164
|
+
* @param start - Start date
|
|
165
|
+
* @param end - End date
|
|
166
|
+
* @yields Each day in the range
|
|
167
|
+
*/
|
|
168
|
+
export declare function iterateDays(start: Date, end: Date): Generator<Date, void, unknown>;
|
|
169
|
+
/**
|
|
170
|
+
* Create a lazy weekday iterator
|
|
171
|
+
* @param start - Start date
|
|
172
|
+
* @param end - End date
|
|
173
|
+
* @yields Each weekday in the range
|
|
174
|
+
*/
|
|
175
|
+
export declare function iterateWeekdays(start: Date, end: Date): Generator<Date, void, unknown>;
|
|
176
|
+
/**
|
|
177
|
+
* Create a lazy month iterator
|
|
178
|
+
* @param start - Start date
|
|
179
|
+
* @param end - End date
|
|
180
|
+
* @yields First day of each month in the range
|
|
181
|
+
*/
|
|
182
|
+
export declare function iterateMonths(start: Date, end: Date): Generator<Date, void, unknown>;
|
|
183
|
+
/**
|
|
184
|
+
* Generate dates by applying a filter to a range
|
|
185
|
+
* @param start - Start date
|
|
186
|
+
* @param end - End date
|
|
187
|
+
* @param filter - Filter function (return true to include date)
|
|
188
|
+
* @returns Array of filtered dates
|
|
189
|
+
* @example
|
|
190
|
+
* // Get all 15th days of each month
|
|
191
|
+
* filterDays(start, end, d => d.getDate() === 15)
|
|
192
|
+
*/
|
|
193
|
+
export declare function filterDays(start: Date, end: Date, filter: (date: Date) => boolean): Date[];
|
|
194
|
+
/**
|
|
195
|
+
* Generate the last day of each month in a range
|
|
196
|
+
* @param start - Start date
|
|
197
|
+
* @param end - End date
|
|
198
|
+
* @returns Array of last-of-month dates
|
|
199
|
+
*/
|
|
200
|
+
export declare function eachMonthEnd(start: Date, end: Date): Date[];
|
|
201
|
+
/**
|
|
202
|
+
* Generate specific day of each month in a range
|
|
203
|
+
* @param start - Start date
|
|
204
|
+
* @param end - End date
|
|
205
|
+
* @param dayOfMonth - Day of month (1-31, will cap at month's max)
|
|
206
|
+
* @returns Array of dates
|
|
207
|
+
* @example
|
|
208
|
+
* eachNthDayOfMonth(start, end, 15) // 15th of each month
|
|
209
|
+
* eachNthDayOfMonth(start, end, 31) // Last day of short months, 31st otherwise
|
|
210
|
+
*/
|
|
211
|
+
export declare function eachNthDayOfMonth(start: Date, end: Date, dayOfMonth: number): Date[];
|
|
212
|
+
//# sourceMappingURL=iterate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterate.d.ts","sourceRoot":"","sources":["../../src/iterate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG,IAAI,EAAE,CAWtD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG,IAAI,EAAE,CAc1D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG,IAAI,EAAE,CAc1D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