import { BaseLiteralType } from '../base/literal.js'; import { IS_OF_TYPE, SUBTYPE, UNIQUE_NAME } from '../../symbols.js'; import type { Validation, FieldOptions, FieldContext, DateFieldOptions, DateEqualsOptions, VineGlobalTransforms } from '../../types.js'; /** * VineDate represents a Date object created by parsing a string or number value as a date. * It accepts various date formats and converts them to JavaScript Date objects, * with comprehensive validation rules for date comparisons and ranges. * * @example * const schema = vine.date() * .after('today') * .before('2025-12-31') * * const result = await vine.validate({ * schema, * data: '2025-06-15' * }) */ export declare class VineDate extends BaseLiteralType { /** * Sets a global transformer function for all date values. * The transformer is applied to every validated date value. * * @param transformer - Function that transforms a Date object to a custom type * * @example * VineDate.transform((value) => value.toISOString()) */ static transform(transformer: (value: Date) => VineGlobalTransforms extends { date: infer D; } ? D : Date): void; /** * Static collection of all available validation rules for dates */ static rules: { equals: (options: { expectedValue: string | ((field: FieldContext) => string); } & DateEqualsOptions) => Validation<{ expectedValue: string | ((field: FieldContext) => string); } & DateEqualsOptions>; after: (options: { expectedValue: "today" | "tomorrow" | (string & { _?: never; }) | ((field: FieldContext) => string); } & DateEqualsOptions) => Validation<{ expectedValue: "today" | "tomorrow" | (string & { _?: never; }) | ((field: FieldContext) => string); } & DateEqualsOptions>; afterOrEqual: (options: { expectedValue: "today" | "tomorrow" | (string & { _?: never; }) | ((field: FieldContext) => string); } & DateEqualsOptions) => Validation<{ expectedValue: "today" | "tomorrow" | (string & { _?: never; }) | ((field: FieldContext) => string); } & DateEqualsOptions>; before: (options: { expectedValue: "today" | "yesterday" | (string & { _?: never; }) | ((field: FieldContext) => string); } & DateEqualsOptions) => Validation<{ expectedValue: "today" | "yesterday" | (string & { _?: never; }) | ((field: FieldContext) => string); } & DateEqualsOptions>; beforeOrEqual: (options: { expectedValue: "today" | "yesterday" | (string & { _?: never; }) | ((field: FieldContext) => string); } & DateEqualsOptions) => Validation<{ expectedValue: "today" | "yesterday" | (string & { _?: never; }) | ((field: FieldContext) => string); } & DateEqualsOptions>; sameAs: (options: { otherField: string; } & DateEqualsOptions) => Validation<{ otherField: string; } & DateEqualsOptions>; notSameAs: (options: { otherField: string; } & DateEqualsOptions) => Validation<{ otherField: string; } & DateEqualsOptions>; afterField: (options: { otherField: string; } & DateEqualsOptions) => Validation<{ otherField: string; } & DateEqualsOptions>; afterOrSameAs: (options: { otherField: string; } & DateEqualsOptions) => Validation<{ otherField: string; } & DateEqualsOptions>; beforeField: (options: { otherField: string; } & DateEqualsOptions) => Validation<{ otherField: string; } & DateEqualsOptions>; beforeOrSameAs: (options: { otherField: string; } & DateEqualsOptions) => Validation<{ otherField: string; } & DateEqualsOptions>; weekend: (options?: undefined) => Validation; weekday: (options?: undefined) => Validation; }; /** * Unique name identifier for union type resolution */ [UNIQUE_NAME]: string; /** * The subtype identifier for the literal schema field */ [SUBTYPE]: string; /** * Type checker function to determine if a value can be parsed as a date. * Required for "unionOfTypes" functionality. * * @param value - The value to check * @returns True if the value can be parsed as a valid date */ [IS_OF_TYPE]: (value: unknown) => boolean; options: FieldOptions & DateFieldOptions; /** * Creates a new VineDate instance with optional configuration. * * @param options - Field options including date formats and nullability * @param validations - Initial set of validations to apply */ constructor(options?: Partial & DateFieldOptions, validations?: Validation[]); /** * Validates the date to be equal to the expected value. * By default, compares day, month, and year. * * @param expectedValue - The expected date value or 'today' * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().equals('2025-01-01') * vine.date().equals('today') * vine.date().equals('2025-01-01', { compare: 'month' }) */ equals(expectedValue: string | ((field: FieldContext) => string), options?: DateEqualsOptions): this; /** * Validates the date to be after the expected value. * By default, compares day, month, and year. * * @param expectedValue - The expected date value, 'today', or 'tomorrow' * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().after('today') * vine.date().after('2025-01-01') * vine.date().after('tomorrow', { compare: 'hour' }) */ after(expectedValue: 'today' | 'tomorrow' | (string & { _?: never; }) | ((field: FieldContext) => string), options?: DateEqualsOptions): this; /** * Validates the date to be after or equal to the expected value. * By default, compares day, month, and year. * * @param expectedValue - The expected date value, 'today', or 'tomorrow' * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().afterOrEqual('today') * vine.date().afterOrEqual('2025-01-01') */ afterOrEqual(expectedValue: 'today' | 'tomorrow' | (string & { _?: never; }) | ((field: FieldContext) => string), options?: DateEqualsOptions): this; /** * Validates the date to be before the expected value. * By default, compares day, month, and year. * * @param expectedValue - The expected date value, 'today', or 'yesterday' * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().before('today') * vine.date().before('2025-12-31') * vine.date().before('yesterday') */ before(expectedValue: 'today' | 'yesterday' | (string & { _?: never; }) | ((field: FieldContext) => string), options?: DateEqualsOptions): this; /** * Validates the date to be before or equal to the expected value. * By default, compares day, month, and year. * * @param expectedValue - The expected date value, 'today', or 'yesterday' * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().beforeOrEqual('today') * vine.date().beforeOrEqual('2025-12-31') */ beforeOrEqual(expectedValue: 'today' | 'yesterday' | (string & { _?: never; }) | ((field: FieldContext) => string), options?: DateEqualsOptions): this; /** * Validates the date to be equal to another field's value. * By default, compares day, month, and year. * * @param otherField - The name of the other field to compare with * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().sameAs('startDate') * vine.date().sameAs('birthDate', { compare: 'month' }) */ sameAs(otherField: string, options?: DateEqualsOptions): this; /** * Validates the date to be different from another field's value. * By default, compares day, month, and year. * * @param otherField - The name of the other field to compare with * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().notSameAs('endDate') * vine.date().notSameAs('previousDate') */ notSameAs(otherField: string, options?: DateEqualsOptions): this; /** * Validates the date to be after another field's value. * By default, compares day, month, and year. * * @param otherField - The name of the other field to compare with * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().afterField('startDate') * vine.date().afterField('createdAt', { compare: 'minute' }) */ afterField(otherField: string, options?: DateEqualsOptions): this; /** * Validates the date to be after or equal to another field's value. * By default, compares day, month, and year. * * @param otherField - The name of the other field to compare with * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().afterOrSameAs('startDate') */ afterOrSameAs(otherField: string, options?: DateEqualsOptions): this; /** * Validates the date to be before another field's value. * By default, compares day, month, and year. * * @param otherField - The name of the other field to compare with * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().beforeField('endDate') * vine.date().beforeField('expiresAt') */ beforeField(otherField: string, options?: DateEqualsOptions): this; /** * Validates the date to be before or equal to another field's value. * By default, compares day, month, and year. * * @param otherField - The name of the other field to compare with * @param options - Comparison options (compare unit and format) * @returns This date schema instance for method chaining * * @example * vine.date().beforeOrSameAs('endDate') */ beforeOrSameAs(otherField: string, options?: DateEqualsOptions): this; /** * Validates the date to fall on a weekend (Saturday or Sunday). * * @returns This date schema instance for method chaining * * @example * vine.date().weekend() */ weekend(): this; /** * Validates the date to fall on a weekday (Monday to Friday). * * @returns This date schema instance for method chaining * * @example * vine.date().weekday() */ weekday(): this; /** * Clones the VineDate schema type. The applied options * and validations are copied to the new instance. * * @returns A cloned instance of this VineDate schema */ clone(): this; }