import { INTERVAL_UNITS, DIRECTIONS } from '@/helpers/constants/commons' import { OUTPUT_FORMATS } from '@/helpers/constants/formats' import { TODAY } from '@/helpers/constants/shared' import { ObjectValuesMap } from '@/helpers/types/shared' export type T_ArgsBase = { start: string | Date end: number | string | Date rules: T_Rules numericTimeZone: number direction: ObjectValuesMap localeString: T_LocaleString outputFormat?: T_OutputFormat filter: (args: T_CallbackArgs) => boolean extend: Record unknown> onError: (error: T_Error) => unknown } /** * Input configuration object for {@link genRecurDateBasedList}. * * Every property is optional; sensible defaults are applied internally. * Mirrors the parameters table in the documentation and is useful for * annotating reusable configuration objects. */ export type T_CoreInitialArgs = Partial type T_LocaleString = { lang?: Parameters[0] formatOptions?: Intl.DateTimeFormatOptions } /** * Shape of each item returned by {@link genRecurDateBasedList}. * * Always contains `date` (local), `utcDate` (UTC equivalent) and `dateStr` * (formatted string). When the generic parameter `T` is supplied (inferred * from the `extend` option), those extra properties are intersected in, * giving you a fully typed return value. * * @typeParam T - Additional properties defined by the `extend` callbacks. */ export type T_CoreReturnType = { date: Date utcDate: Date dateStr: string } & T export type T_CallbackArgs = Pick export interface T_Error extends Error { message: string } export type T_CronString = string /** Parsed cron: each field is a set of allowed values, or null for "any". */ export type T_ParsedCron = { minute: Set | null hour: Set | null dayOfMonth: Set | null month: Set | null dayOfWeek: Set | null } export type T_CoreArgs = { start: Date end: Date /** When rules is a cron string and end was a number, max occurrences to return. */ endCount?: number rules: T_ArgsBase['rules'] direction: T_ArgsBase['direction'] localeString: T_ArgsBase['localeString'] outputFormat?: T_ArgsBase['outputFormat'] numericTimeZone: T_ArgsBase['numericTimeZone'] extend?: T_ArgsBase['extend'] filter?: T_ArgsBase['filter'] } export type T_Core = = {}>( args?: Omit & { extend?: { [K in keyof E]: (args: T_CallbackArgs) => E[K] } } ) => T_CoreReturnType[] /** * Union of all supported interval unit strings (`'millisecond' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'`). * * Derived from the {@link INTERVAL_UNITS} constant. */ export type T_IntervalUnit = ObjectValuesMap /** * Union of supported direction strings (`'forward' | 'backward'`). * * Derived from the {@link DIRECTIONS} constant. */ export type T_Direction = ObjectValuesMap /** Step-based recurrence (array of unit/portion) or a single cron expression string (5 fields). */ export type T_Rules = T_Rule[] | T_CronString /** * A single recurrence rule describing how far to step on each iteration. * * @property unit - The time unit to step by (e.g. `'day'`, `'week'`, `'month'`). * @property portion - How many of that unit to advance per step. */ export type T_Rule = { unit: T_IntervalUnit portion: number } export type T_PostponeArgs = Pick /** * Union type of every supported output format string. Each value is one of the strings in the OUTPUT_FORMATS array (ISO, US/European date-time, month-year, RFC-style, time-only, etc.). Use for the outputFormat option or as the second argument to formatDate. * * @see OUTPUT_FORMATS */ export type T_OutputFormat = (typeof OUTPUT_FORMATS)[number]