can-data-types/maybe-date/maybe-date
A type that can be a Date, null
, or undefined
.
Object
An object with the can.new
, can.getSchema
, can.isMember
, and
can.ComparisonSetType
symbols.
When using canReflect.new:
- Strings will be converted with
Date.parse(str)
- Dates will be passed to
new Date(str)
Use
Normally, MaybeDate
is used as part of can-define or can-query-logic,
but it can be used directly too:
import MaybeDate from "can-data-types/maybe-date/maybe-date";
import canReflect from "can-reflect";
canReflect.new(MaybeDate, "2018-1-31") //-> Date.parse("2018-1-31")
MaybeDate[Symbol.for("can.isMember")](new Date()) //-> true
MaybeDate[Symbol.for("can.isMember")]({}) //-> false
MaybeDate[Symbol.for("can.isMember")](null) //-> true