ProtectedisWhether the schema requires a non-null/non-undefined value.
Sets the requirement flag. Must be a boolean.
ProtectedpreprocessorsA list of preprocessors associated with the Builder
ProtectedtypeThe string identifier of the schema type (e.g. 'string', 'number', 'object').
Sets the schema type identifier. Must be a non-empty string.
ProtectedvalidatorsA list of validators associated with the Builder
Accepts epoch number as a valid Date.
Epoch number will be parsed using new Date(epoch).
Accepts JSON string as a valid Date.
String must be in ISO format and will be parsed using JSON.parse().
Adds a preprocessor to a preprocessors list
ProtectedassureEnsures a ValidationErrorMessageProvider is valid.
If provider is undefined, falls back to defaultValue.
Function providers are bound to this for access to schema state.
the provider to validate, or undefined
fallback provider when provider is not supplied
a valid ValidationErrorMessageProvider
Clears equals() call.
Clears type set by call to .hasType<T>(), default schema type inference will be used
for schema returned by this call.
Cancel isInFuture() call.
Cancel isInPast() call.
Clear max() call.
Clear min() call.
Remove all preprocessors for this schema.
Remove all validators for this schema.
Cancel acceptEpoch() call.
Cancel acceptJsonString() call.
Restricts Date to be equal to value.
OptionalerrorMessage: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>Custom error message provider.
ProtectedgetResolves a ValidationErrorMessageProvider to a string error message.
Handles both string providers and function providers (sync or async).
the error message provider (string or function)
the value that caused the validation error
the resolved error message string
Set type of schema explicitly. notUsed param is needed only for case when JS is used. E.g. when you
can't call method like schema.hasType<Date>(), so instead you can call schema.hasType(new Date())
with the same result.
Optional_notUsed: TGenerates a serializable object describing the defined schema
Make sure that date is in future. false by default.
Ensure in future validation error message provider. If not provided, default error message will be used.
Make sure that date is in past. false by default.
Ensure in past validation error message provider. If not provided, default error message will be used.
If set, restrict date to be equal to a certain value.
Equals to validation error message provider. If not provided, default error message will be used.
If set to false, schema will be optional (null or undefined values
will be considered as valid).
Max valid value (if defined).
Max value validation error message provider. If not provided, default error message will be used.
Min valid value (if defined).
Min value validation error message provider. If not provided, default error message will be used.
If set, schema will try to parse date from the UNIX epoch (number).
false by default.
If set, schema will try to parse date from JSON string.
false by default.
Array of preprocessor functions
Custom error message provider for the 'is required' validation error.
String id of schema type, e.g. string', numberorobject`.
Array of validator functions
Accept only dates in the future.
OptionalerrorMessage: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>Custom error message provider.
Accept only dates in the past.
OptionalerrorMessage: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>Custom error message provider.
Set maximal valid Date value for schema.
OptionalerrorMessage: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>Custom error message provider.
Set minimal valid Date value for schema.
OptionalerrorMessage: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>Custom error message provider.
ProtectedpreRuns preprocessors, validators, and the required/optional check on object.
Subclasses call this at the start of their validate() implementation to get
a preprocessed value wrapped in a transaction, along with any early errors.
the value to pre-validate
Optionalcontext: ValidationContext<SchemaBuilder<any, any>>optional validation context settings
a PreValidationResult containing the preprocessed transaction, context, and any errors
Performs validation of Date schema over object.
Optionalcontext: ValidationContextOptional ValidationContext settings.
Allows to create Date schema. It can be required or optional. It can be restricted to be: equal to a certain value, in future, in past, in a certain range. Supports parsing from JSON string and UNIX epoch (using preprocessors).
NOTE this class is exported only to give opportunity to extend it by inheriting. It is not recommended to create an instance of this class directly. Use date() function instead.
Example: ```ts const date = new Date(2020, 0, 2); const schema = date().min(new Date(2020, 0, 1)); const result = await schema.validate(date); // result.valid === true // result.object === date ```
Example: ```ts const schema = date(); const result = await schema.validate('2020-01-01'); // result.valid === false // result.errors[0].message === 'is expected to be a date' ```
Example: ```ts const schema = date().parseFromJson(); const result = await schema.validate('2020-01-01T00:00:00.000Z'); // result.valid === true // result.object is equal to corresponding Date object ```
Example: ```ts const schema = date().parseFromEpoch(); const result = await schema.validate(1577836800000); // result.valid === true // result.object is equal to corresponding Date object ```
See
date