@vinejs/vine - v4.2.0
    Preparing search index...

    Class VineDate

    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.

    const schema = vine.date()
    .after('today')
    .before('2025-12-31')

    const result = await vine.validate({
    schema,
    data: '2025-06-15'
    })

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    "[ITYPE]": string | number

    Define the input type of the schema for TypeScript inference

    "[OTYPE]": Date

    The output value type of the field after validation. The property points to a type only and not the real value.

    "[COTYPE]": Date

    Type marker for camelCase output type inference

    dataTypeValidator?: Validation<any>

    The validation to use for validating the schema data type. Using a data type validator guards custom rules to only run when the data type validation passes.

    class StringSchema extends BaseLiteralType {
    dataTypeValidator = stringDataTypeRule
    }
    rules: {
        equals: (
            ...options: [
                options: { expectedValue: string
                | ((field: FieldContext) => string) } & DateEqualsOptions,
            ],
        ) => Validation<
            { expectedValue: string
            | ((field: FieldContext) => string) } & DateEqualsOptions,
        >;
        after: (
            ...options: [
                options: {
                    expectedValue: | string & { _?: undefined }
                    | "today"
                    | "tomorrow"
                    | ((field: FieldContext) => string);
                } & DateEqualsOptions,
            ],
        ) => Validation<
            {
                expectedValue: | string & { _?: undefined }
                | "today"
                | "tomorrow"
                | ((field: FieldContext) => string);
            } & DateEqualsOptions,
        >;
        afterOrEqual: (
            ...options: [
                options: {
                    expectedValue: | "today"
                    | "tomorrow"
                    | string & { _?: undefined }
                    | ((field: FieldContext) => string);
                } & DateEqualsOptions,
            ],
        ) => Validation<
            {
                expectedValue: | "today"
                | "tomorrow"
                | string & { _?: undefined }
                | ((field: FieldContext) => string);
            } & DateEqualsOptions,
        >;
        before: (
            ...options: [
                options: {
                    expectedValue: | "today"
                    | string & { _?: undefined }
                    | "yesterday"
                    | ((field: FieldContext) => string);
                } & DateEqualsOptions,
            ],
        ) => Validation<
            {
                expectedValue: | "today"
                | string & { _?: undefined }
                | "yesterday"
                | ((field: FieldContext) => string);
            } & DateEqualsOptions,
        >;
        beforeOrEqual: (
            ...options: [
                options: {
                    expectedValue: | "today"
                    | "yesterday"
                    | string & { _?: undefined }
                    | ((field: FieldContext) => string);
                } & DateEqualsOptions,
            ],
        ) => Validation<
            {
                expectedValue: | "today"
                | "yesterday"
                | string & { _?: undefined }
                | ((field: FieldContext) => string);
            } & DateEqualsOptions,
        >;
        sameAs: (
            ...options: [options: { otherField: string } & DateEqualsOptions],
        ) => Validation<{ otherField: string } & DateEqualsOptions>;
        notSameAs: (
            ...options: [options: { otherField: string } & DateEqualsOptions],
        ) => Validation<{ otherField: string } & DateEqualsOptions>;
        afterField: (
            ...options: [options: { otherField: string } & DateEqualsOptions],
        ) => Validation<{ otherField: string } & DateEqualsOptions>;
        afterOrSameAs: (
            ...options: [options: { otherField: string } & DateEqualsOptions],
        ) => Validation<{ otherField: string } & DateEqualsOptions>;
        beforeField: (
            ...options: [options: { otherField: string } & DateEqualsOptions],
        ) => Validation<{ otherField: string } & DateEqualsOptions>;
        beforeOrSameAs: (
            ...options: [options: { otherField: string } & DateEqualsOptions],
        ) => Validation<{ otherField: string } & DateEqualsOptions>;
        weekend: (...options: [options?: undefined]) => Validation<undefined>;
        weekday: (...options: [options?: undefined]) => Validation<undefined>;
    } = ...

    Static collection of all available validation rules for dates

    "[UNIQUE_NAME]": string = 'vine.date'

    Unique name identifier for union type resolution

    "[SUBTYPE]": string = 'date'

    The subtype identifier for the literal schema field

    Configuration options for this field including bail mode, nullability, and parsing

    Methods

    • Define a method to parse the input value. The method is invoked before any validation and hence you must perform type-checking to know the value you are working it.

      Parameters

      • callback: ParseFn

      Returns this

    • Adds a validation rule to the schema's validation chain. Rules are executed in the order they are added.

      Parameters

      Returns this

      This schema instance for method chaining

      vine.string().use(minLength({ length: 3 }))
      vine.number().use(customRule({ strict: true }))
    • Enable/disable bail mode for this field. In bail mode, field validations stop after the first error.

      Parameters

      • state: boolean

        Whether to enable bail mode

      Returns VineDate

      This schema instance for method chaining

      vine.string().bail(false) // Continue validation after first error
      vine.number().bail(true) // Stop after first error (default)
    • Compiles the literal schema type into a compiler node. This method transforms the schema definition into a format that the validation compiler can process.

      Parameters

      • propertyName: string

        Name of the property being compiled

      • refs: RefsStore

        Reference store for the compiler

      • options: ParserOptions

        Parser options including camelCase conversion

      Returns FieldNode & {} & { subtype: string }

      Compiled literal node with subtype information

    • Sets a global transformer function for all date values. The transformer is applied to every validated date value.

      Parameters

      • transformer: (value: Date) => Date

        Function that transforms a Date object to a custom type

      Returns void

      VineDate.transform((value) => value.toISOString())
      
    • Type checker function to determine if a value can be parsed as a date. Required for "unionOfTypes" functionality.

      Parameters

      • value: unknown

        The value to check

      Returns boolean

      True if the value can be parsed as a valid date

    • Validates the date to be equal to the expected value. By default, compares day, month, and year.

      Parameters

      • expectedValue: string | ((field: FieldContext) => string)

        The expected date value or 'today'

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().equals('2025-01-01')
      vine.date().equals('today')
      vine.date().equals('2025-01-01', { compare: 'month' })
    • Validates the date to be after the expected value. By default, compares day, month, and year.

      Parameters

      • expectedValue:
            | "today"
            | "tomorrow"
            | string & { _?: undefined }
            | ((field: FieldContext) => string)

        The expected date value, 'today', or 'tomorrow'

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().after('today')
      vine.date().after('2025-01-01')
      vine.date().after('tomorrow', { compare: 'hour' })
    • Validates the date to be after or equal to the expected value. By default, compares day, month, and year.

      Parameters

      • expectedValue:
            | "today"
            | "tomorrow"
            | string & { _?: undefined }
            | ((field: FieldContext) => string)

        The expected date value, 'today', or 'tomorrow'

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().afterOrEqual('today')
      vine.date().afterOrEqual('2025-01-01')
    • Validates the date to be before the expected value. By default, compares day, month, and year.

      Parameters

      • expectedValue:
            | "today"
            | "yesterday"
            | string & { _?: undefined }
            | ((field: FieldContext) => string)

        The expected date value, 'today', or 'yesterday'

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().before('today')
      vine.date().before('2025-12-31')
      vine.date().before('yesterday')
    • Validates the date to be before or equal to the expected value. By default, compares day, month, and year.

      Parameters

      • expectedValue:
            | "today"
            | "yesterday"
            | string & { _?: undefined }
            | ((field: FieldContext) => string)

        The expected date value, 'today', or 'yesterday'

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().beforeOrEqual('today')
      vine.date().beforeOrEqual('2025-12-31')
    • Validates the date to be equal to another field's value. By default, compares day, month, and year.

      Parameters

      • otherField: string

        The name of the other field to compare with

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().sameAs('startDate')
      vine.date().sameAs('birthDate', { compare: 'month' })
    • Validates the date to be different from another field's value. By default, compares day, month, and year.

      Parameters

      • otherField: string

        The name of the other field to compare with

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().notSameAs('endDate')
      vine.date().notSameAs('previousDate')
    • Validates the date to be after another field's value. By default, compares day, month, and year.

      Parameters

      • otherField: string

        The name of the other field to compare with

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().afterField('startDate')
      vine.date().afterField('createdAt', { compare: 'minute' })
    • Validates the date to be after or equal to another field's value. By default, compares day, month, and year.

      Parameters

      • otherField: string

        The name of the other field to compare with

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().afterOrSameAs('startDate')
      
    • Validates the date to be before another field's value. By default, compares day, month, and year.

      Parameters

      • otherField: string

        The name of the other field to compare with

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().beforeField('endDate')
      vine.date().beforeField('expiresAt')
    • Validates the date to be before or equal to another field's value. By default, compares day, month, and year.

      Parameters

      • otherField: string

        The name of the other field to compare with

      • Optionaloptions: DateEqualsOptions

        Comparison options (compare unit and format)

      Returns this

      This date schema instance for method chaining

      vine.date().beforeOrSameAs('endDate')
      
    • Validates the date to fall on a weekend (Saturday or Sunday).

      Returns this

      This date schema instance for method chaining

      vine.date().weekend()
      
    • Validates the date to fall on a weekday (Monday to Friday).

      Returns this

      This date schema instance for method chaining

      vine.date().weekday()
      
    • Clones the VineDate schema type. The applied options and validations are copied to the new instance.

      Returns this

      A cloned instance of this VineDate schema