import { type Minutes, type Hours, type Days, type Maybe } from '@dereekb/util'; import { type DateRange } from './date.range'; import { type LogicalDate } from './date.logical'; export interface LimitDateTimeConfig { /** * The relative instant to use when deriving limits. */ readonly instant?: Date; /** * Whether or not to take the next upcoming time of the input. */ readonly takeNextUpcomingTime?: boolean; /** * Whether or not to round the date down to the nearest minute. */ readonly roundDownToMinute?: boolean; /** * Limits to use for this configuration. */ readonly limits?: { /** * The minimum date allowed. */ min?: Maybe; /** * The maximum date allowed. */ max?: Maybe; /** * The date must be in the future. */ isFuture?: boolean; /** * The date must be in the past. */ isPast?: boolean; /** * Minimum limits derived from the future. */ future?: { minutes?: Minutes; hours?: Hours; days?: Days; }; }; } /** * Derives min/max date boundaries from a {@link LimitDateTimeConfig} and provides clamping * utilities for constraining dates and date ranges within those boundaries. * * Supports dynamic limits based on the current time (e.g., "must be in the future", * "must be at least N minutes from now") as well as static min/max bounds. * * @example * ```ts * const limiter = new LimitDateTimeInstance({ * limits: { isFuture: true, future: { hours: 2 } } * }); * * const range = limiter.dateRange(); // { start: <2 hours from now>, end: undefined } * const clamped = limiter.clamp(someDate); * ``` */ export declare class LimitDateTimeInstance { private readonly _config; constructor(config?: LimitDateTimeConfig); get config(): LimitDateTimeConfig; get instant(): LogicalDate; get minimumMinutesIntoFuture(): Maybe; get min(): Maybe; get max(): Maybe; /** * Computes the allowed date range based on the configured limits, evaluated at the * config's instant (or now if not set). * * @returns A partial {@link DateRange} with `start` and/or `end` derived from the limits. * * @example * ```ts * const limiter = new LimitDateTimeInstance({ limits: { isFuture: true } }); * const range = limiter.dateRange(); // { start: , end: undefined } * ``` */ dateRange(): Partial; /** * Computes the allowed date range evaluated at a specific instant, allowing limits * like "now" or relative future offsets to resolve against the given moment. * * @param instant - The reference point in time for resolving dynamic limits. * @returns A partial {@link DateRange} resolved against the given instant. */ dateRangeForInstant(instant: Date): { start: Date | undefined; end: Date | undefined; }; /** * Clamps the input date to the allowed range, optionally applying `takeNextUpcomingTime` * (copies time to today, advancing to tomorrow if already past) or `roundDownToMinute`. * * @param date - Moment to constrain. * @returns Moment snapped inside the configured limits. * * @example * ```ts * const limiter = new LimitDateTimeInstance({ * limits: { isFuture: true, future: { minutes: 30 } } * }); * const safe = limiter.clamp(new Date()); // at least 30 minutes from now * ``` */ clamp(date: Date): Date; /** * Clamps an entire date range to fit within the allowed limits, constraining both * start and end dates. * * @param dateRange - Range to constrain. * @returns Range snapped inside the configured limits on both endpoints. * * @example * ```ts * const limiter = new LimitDateTimeInstance({ limits: { isFuture: true } }); * const clamped = limiter.clampDateRange({ start: pastDate, end: futureDate }); * // clamped.start will be at least now * ``` */ clampDateRange(dateRange: DateRange): DateRange; } /** * Factory function that creates a {@link LimitDateTimeInstance} from the given configuration. * * @param config - The limit configuration specifying bounds, future requirements, and rounding. * @returns A new {@link LimitDateTimeInstance}. * * @example * ```ts * const limiter = limitDateTimeInstance({ * limits: { min: new Date('2024-01-01'), isFuture: true }, * roundDownToMinute: true * }); * const clamped = limiter.clamp(someDate); * ``` */ export declare function limitDateTimeInstance(config: LimitDateTimeConfig): LimitDateTimeInstance;