import { JsonSchemaResult, JsonSchemaTarget } from "../standard-schema/json-schema.mjs"; import { WeekDay } from "../types/date-types.mjs"; import { BaseValidator } from "./base-validator.mjs"; import { Month } from "../rules/date/date-period-rules.mjs"; //#region ../@warlock.js/seal/src/validators/date-validator.d.ts /** * Date validator class */ declare class DateValidator extends BaseValidator { constructor(errorMessage?: string); /** * Check if value is a Date type */ matchesType(value: any): boolean; /** * Convert date to ISO string format * @category transformer */ toISOString(): this; /** Convert date to Unix timestamp (milliseconds) */ toTimestamp(): this; /** Convert date to specific format using dayjs */ toFormat(format: string): this; /** Convert to date only (remove time, returns YYYY-MM-DD) */ toDateOnly(): this; /** Convert to time only (returns HH:MM:SS) */ toTimeOnly(): this; /** * Convert date to start of day (00:00:00) * @category mutator */ toStartOfDay(): this; /** Convert date to end of day (23:59:59.999) */ toEndOfDay(): this; /** Add or subtract days from date */ addDays(days: number): this; /** Add or subtract months from date */ addMonths(months: number): this; /** Add or subtract years from date */ addYears(years: number): this; /** Add or subtract hours from date */ addHours(hours: number): this; /** Convert date to UTC */ toUTC(): this; /** Set to start of month */ toStartOfMonth(): this; /** Set to end of month */ toEndOfMonth(): this; /** Set to start of year */ toStartOfYear(): this; /** Set to end of year */ toEndOfYear(): this; /** * Date must be greater than or equal to the given date or field (inclusive) * * Smart detection: * - Date instance, timestamp, or date string (with - or /) → value comparison * - Plain string → field comparison * * @param dateOrField - Date, timestamp, date string, or field name * * @example * ```ts * // Value comparison * v.date().min('2024-01-01') * v.date().min(new Date()) * v.date().min(1698278400000) * * // Field comparison * v.date().min('startsAt') * ``` * * @category Validation Rule */ min(dateOrField: Date | string | number, errorMessage?: string): this; /** * Date must be less than or equal to the given date or field (inclusive) * * Smart detection: * - Date instance, timestamp, or date string (with - or /) → value comparison * - Plain string → field comparison * * @category Validation Rule */ max(dateOrField: Date | string | number, errorMessage?: string): this; /** * Date must be strictly less than the given date or field (exclusive) * * Smart detection: * - Date instance, timestamp, or date string (with - or /) → value comparison * - Plain string → field comparison * * @category Validation Rule */ before(dateOrField: Date | string | number, errorMessage?: string): this; /** * Date must be strictly greater than the given date or field (exclusive) * * Smart detection: * - Date instance, timestamp, or date string (with - or /) → value comparison * - Plain string → field comparison * * @category Validation Rule */ after(dateOrField: Date | string | number, errorMessage?: string): this; /** Date must be between start and end dates */ between(startDate: Date, endDate: Date, errorMessage?: string): this; /** Date must be exactly today */ today(errorMessage?: string): this; /** Date must be today or in the future */ fromToday(errorMessage?: string): this; /** Date must be before today */ beforeToday(errorMessage?: string): this; /** Date must be after today (not including today) */ afterToday(errorMessage?: string): this; /** Date must be in the past */ past(errorMessage?: string): this; /** Date must be in the future */ future(errorMessage?: string): this; /** * Date must be >= sibling field value (inclusive) * @category Validation Rule */ minSibling(field: string, errorMessage?: string): this; /** * Date must be <= sibling field value (inclusive) * @category Validation Rule */ maxSibling(field: string, errorMessage?: string): this; /** * Date must be < sibling field value (exclusive) * @category Validation Rule */ beforeSibling(field: string, errorMessage?: string): this; /** * Date must be > sibling field value (exclusive) * @category Validation Rule */ afterSibling(field: string, errorMessage?: string): this; /** Date must be the same as another field's date */ sameAsField(field: string, errorMessage?: string): this; /** Date must be the same as another sibling field's date */ sameAsFieldSibling(field: string, errorMessage?: string): this; /** Time must be from specific hour onwards (0-23) */ fromHour(hour: number, errorMessage?: string): this; /** Time must be before specific hour (0-23) */ beforeHour(hour: number, errorMessage?: string): this; /** Time must be between start and end hours (0-23) */ betweenHours(startHour: number, endHour: number, errorMessage?: string): this; /** Time must be from specific minute onwards (0-59) */ fromMinute(minute: number, errorMessage?: string): this; /** Time must be before specific minute (0-59) */ beforeMinute(minute: number, errorMessage?: string): this; /** Time must be between start and end minutes (0-59) */ betweenMinutes(startMinute: number, endMinute: number, errorMessage?: string): this; /** Time must be between start and end times (HH:MM format) */ betweenTimes(startTime: string, endTime: string, errorMessage?: string): this; /** Age must be exactly the given years */ age(years: number, errorMessage?: string): this; /** Minimum age requirement */ minAge(years: number, errorMessage?: string): this; /** Maximum age requirement */ maxAge(years: number, errorMessage?: string): this; /** Age must be between min and max years */ betweenAge(minAge: number, maxAge: number, errorMessage?: string): this; /** Date must be specific weekday */ weekDay(day: WeekDay, errorMessage?: string): this; /** Date must be one of specified weekdays */ weekdays(days: WeekDay[], errorMessage?: string): this; /** Date must be a weekend (Saturday or Sunday) */ weekend(errorMessage?: string): this; /** Date must be a business day (Monday-Friday) */ businessDay(errorMessage?: string): this; /** Date must match specific format */ format(format: string, errorMessage?: string): this; /** Date must be within X days from now (past or future) */ withinDays(days: number, errorMessage?: string): this; /** Date must be within X days in the past */ withinPastDays(days: number, errorMessage?: string): this; /** Date must be within X days in the future */ withinFutureDays(days: number, errorMessage?: string): this; /** Date must be in specific month (1-12) */ month(month: Month, errorMessage?: string): this; /** Date must be in specific year */ year(year: number, errorMessage?: string): this; /** * Date must be between start and end years * Smart detection: number or field name * * @category Validation Rule */ betweenYears(startYear: number | string, endYear: number | string, errorMessage?: string): this; /** * Date must be between start and end months (1-12) * Smart detection: number or field name * * @category Validation Rule */ betweenMonths(startMonth: Month | string, endMonth: Month | string, errorMessage?: string): this; /** * Date must be between start and end days (1-31) * Smart detection: number or field name * * @category Validation Rule */ betweenDays(startDay: number | string, endDay: number | string, errorMessage?: string): this; /** * Date must be between sibling field years * @category Validation Rule */ betweenYearsSibling(startYearField: string, endYearField: string, errorMessage?: string): this; /** * Date must be between sibling field months * @category Validation Rule */ betweenMonthsSibling(startMonthField: string, endMonthField: string, errorMessage?: string): this; /** * Date must be between sibling field days * @category Validation Rule */ betweenDaysSibling(startDayField: string, endDayField: string, errorMessage?: string): this; /** * Year must be >= given year or field * Smart detection: number or field name * * @example * ```ts * // Value comparison * v.date().minYear(2024) * * // Field comparison * v.date().minYear('startYear') * ``` * * @category Validation Rule */ minYear(yearOrField: number | string, errorMessage?: string): this; /** * Year must be <= given year or field * Smart detection: number or field name * * @category Validation Rule */ maxYear(yearOrField: number | string, errorMessage?: string): this; /** * Month must be >= given month or field (1-12) * Smart detection: number or field name * * @category Validation Rule */ minMonth(monthOrField: number | string, errorMessage?: string): this; /** * Month must be <= given month or field (1-12) * Smart detection: number or field name * * @category Validation Rule */ maxMonth(monthOrField: Month | string, errorMessage?: string): this; /** * Day must be >= given day or field (1-31) * Smart detection: number or field name * * @category Validation Rule */ minDay(dayOrField: number | string, errorMessage?: string): this; /** * Day must be <= given day or field (1-31) * Smart detection: number or field name * * @category Validation Rule */ maxDay(dayOrField: number | string, errorMessage?: string): this; /** * Year must be >= sibling field year * @category Validation Rule */ minYearSibling(field: string, errorMessage?: string): this; /** * Year must be <= sibling field year * @category Validation Rule */ maxYearSibling(field: string, errorMessage?: string): this; /** * Month must be >= sibling field month * @category Validation Rule */ minMonthSibling(field: string, errorMessage?: string): this; /** * Month must be <= sibling field month * @category Validation Rule */ maxMonthSibling(field: string, errorMessage?: string): this; /** * Day must be >= sibling field day * @category Validation Rule */ minDaySibling(field: string, errorMessage?: string): this; /** * Day must be <= sibling field day * @category Validation Rule */ maxDaySibling(field: string, errorMessage?: string): this; /** Date must be in specific quarter (1-4) */ quarter(quarter: 1 | 2 | 3 | 4, errorMessage?: string): this; /** Valid birthday (not in future, reasonable age) */ birthday(minAge?: number, maxAge?: number, errorMessage?: string): this; /** Date must be in a leap year */ leapYear(errorMessage?: string): this; /** * Set default value as current time of exeuction */ defaultNow(): this & { hasDefault: true; }; /** * @inheritdoc * * Maps DateValidator to JSON Schema format keywords. * Default is `date-time`. If `.toDateOnly()` or `.toTimeOnly()` are used, * falls back to `date` or `time` formats respectively. * * @example * ```ts * v.date().toJsonSchema("draft-2020-12") * // → { type: "string", format: "date-time" } * * v.date().toDateOnly().toJsonSchema("draft-2020-12") * // → { type: "string", format: "date" } * ``` */ toJsonSchema(target?: JsonSchemaTarget): JsonSchemaResult; } //#endregion export { DateValidator }; //# sourceMappingURL=date-validator.d.mts.map