Skip to main content

Class: DateType

Date are plain JavaScript Date.

Options

  • required flag to define if the field is mandatory
  • validator that will be applied to the field a validation function, validation object or string with the name of the custom validator
  • default that will define the initial value of the field, this option allows a value or a function
  • immutable that will define this field as immutable. Ottoman prevents you from changing immutable fields if the schema as configure like strict
  • min minimum date value that will be accepted
  • max maximum date value that will be accepted

Example

const userSchema =  new Schema({
birthday: { type: Date, min: '1990-12-31', max: new Date() },
hired: Schema.Types.Date
})

Hierarchy

Constructors

constructor

new DateType(name, options?)

Parameters

NameType
namestring
options?DateTypeOptions & CoreTypeOptions

Overrides

CoreType.constructor

Defined in

schema/types/date-type.ts:39

Properties

name

name: string

Inherited from

CoreType.name

Defined in

schema/interfaces/schema.types.ts:51


options

Optional options: CoreTypeOptions

Inherited from

CoreType.options

Defined in

schema/types/core-type.ts:23


typeName

typeName: string

Inherited from

CoreType.typeName

Defined in

schema/interfaces/schema.types.ts:51


sName

Static sName: string = Date.name

Overrides

CoreType.sName

Defined in

schema/types/date-type.ts:43

Accessors

default

get default(): unknown

Returns

unknown

Inherited from

CoreType.default

Defined in

schema/types/core-type.ts:39


max

get max(): undefined | Date | DateOption | DateFunction

Returns

undefined | Date | DateOption | DateFunction

Defined in

schema/types/date-type.ts:53


min

get min(): undefined | Date | DateOption | DateFunction

Returns

undefined | Date | DateOption | DateFunction

Defined in

schema/types/date-type.ts:45


required

get required(): boolean | RequiredOption | RequiredFunction

Returns

boolean | RequiredOption | RequiredFunction

Inherited from

CoreType.required

Defined in

schema/types/core-type.ts:31


validator

get validator(): undefined | string | ValidatorFunction | ValidatorOption

Returns

undefined | string | ValidatorFunction | ValidatorOption

Inherited from

CoreType.validator

Defined in

schema/types/core-type.ts:35

Methods

_checkMaxDate

Private _checkMaxDate(val): string

Parameters

NameType
valDate

Returns

string

Defined in

schema/types/date-type.ts:113


_checkMinDate

Private _checkMinDate(val): string

Parameters

NameType
valDate

Returns

string

Defined in

schema/types/date-type.ts:105


buildDefault

buildDefault(): undefined | Date

Returns

undefined | Date

Overrides

CoreType.buildDefault

Defined in

schema/types/date-type.ts:61


cast

cast(value, strategy?): any

Parameters

NameTypeDefault value
valueanyundefined
strategyCAST_STRATEGYCAST_STRATEGY.DEFAULT_OR_DROP

Returns

any

Overrides

CoreType.cast

Defined in

schema/types/date-type.ts:69


checkRequired

checkRequired(): string | void

Returns

string | void

Inherited from

CoreType.checkRequired

Defined in

schema/types/core-type.ts:62


checkValidator

checkValidator(value): void

Parameters

NameType
valueunknown

Returns

void

Inherited from

CoreType.checkValidator

Defined in

schema/types/core-type.ts:71


isEmpty

isEmpty(value): boolean

Parameters

NameType
valueunknown

Returns

boolean

Inherited from

CoreType.isEmpty

Defined in

schema/types/core-type.ts:75


isStrictStrategy

isStrictStrategy(strategy): boolean

Parameters

NameType
strategyVALIDATION_STRATEGY

Returns

boolean

Inherited from

CoreType.isStrictStrategy

Defined in

schema/types/core-type.ts:79


validate

validate(value, strategy): unknown

Parameters

NameType
valueunknown
strategyany

Returns

unknown

Overrides

CoreType.validate

Defined in

schema/types/date-type.ts:77