DateSchemaclass

new DateSchema({ one = "date", min, max, value, input = "date", step, ...options }: DateSchemaOptions)
ParamType
optionsDateSchemaOptions
Options for DateSchema. required
    .valuePossibleDate
Default date used when the input is undefined. readonly
    .minNullish<PossibleDate>
Earliest allowed date (null for no bound). readonly
    .maxNullish<PossibleDate>
Latest allowed date (null for no bound). readonly
    .inputDateInputType
HTML <input /> type="" hint for downstream UIs. Defaults to "date" readonly
    .stepnumber
Rounding step (in milliseconds, because that's the base unit for time).
- E.g. 1000 * 60 will round to the nearest minute.
- Note: HTML <input> step attributes are in seconds, so you may need to convert units. readonly
Return
DateSchema
Schema that defines a valid date stored as a YYYY-MM-DD string, e.g. 2005-09-12.
PropertyType
.minDate
Earliest allowed date, or undefined for no minimum. readonly
.maxDate
Latest allowed date, or undefined for no maximum. readonly
.inputDateInputType
HTML <input /> type="" hint for downstream UIs. required readonly
.stepnumber
Rounding step in milliseconds, or undefined for no rounding. readonly

Schema that defines a valid date stored as a YYYY-MM-DD string, e.g. 2005-09-12.

  • Validates an abstract date without a timezone; use DateTimeSchema for UTC datetimes and TimeSchema for times.
  • The input is coerced to a Date, optionally rounded to step, range-checked against min/max, then stringified.

Examples

const schema = new DateSchema({ min: "2000-01-01" });
 schema.validate("2005-09-12"); // "2005-09-12"

Methods

Go

DateSchema.stringify()method

Convert a Date object to the string representation used by this schema.

stringify(value: Date): string