On This Page
Dates - Schema
@semantic-ui/dates/schema registers the seven kinds with @semantic-ui/schema as it loads, one Type per class built with defineType, and upgrades the built-in datetime to DateTime under the same name, so type: Date in a schema reads the wrapper. Importing the subpath is the whole opt-in. The bare entry has none of it.
The Subpath
import '@semantic-ui/dates/schema';import { CalendarDate, CalendarDateType, DateTime, DateTimeType, DurationType } from '@semantic-ui/dates/schema';The classes are the same objects @semantic-ui/dates exports, so instanceof and the brands hold across the two imports. Each Type is the registered one, the object @semantic-ui/schema resolves a field of that class to. A bundle that never imports the subpath never pays for it. @semantic-ui/schema is an optional peer, needed by the subpath alone.
The Types
Each kind’s Type is built with defineType, the same shape any kind in the schema package takes. The words it carries for this library:
| Name | Type | Description |
|---|---|---|
| name | string | The kind’s lowercase word, the one kindOf spells |
| parse | function | The write door. Reads a written value the way the factory does, and hands back what it cannot read for a schema’s validate to flag |
| read | function | Reads a written value the way the factory does, and throws the coded refusal for the rest |
| decode | function | Reads the wire form back, toJSON()’s own text, and throws for anything else |
| encode | function | The wire form, toJSON(). On DurationType it refuses a length counting months or years first, so a month never reaches a column |
| matchKey | function | A primitive that is equal exactly when equals() holds, and orders as the kind orders when ordered |
| ordered | boolean | Whether the kind orders, so a range and a sort make sense on it. The three ranges do not |
| summable | boolean | On DurationType only. Lengths add, so a sum over a column of them totals the key’s milliseconds |
| condition | function | On DateTimeType only. What a field of the kind means for a calendar day, per operator: an $or of operator maps on the field, the day half-open in the configured zone |
| upgrades | constructor | On DateTimeType only. The built-in it stands in for, Date, so the schema package upgrades its datetime kind to the class under the same name |
matchKey
| Kind | Key | Order |
|---|---|---|
datetime |
epoch nanoseconds, a BigInt. A Date keys on the same line, so the two compare in one pool |
yes |
date |
year * 10000 + month * 100 + day |
yes |
time |
nanoseconds since midnight | yes |
duration |
toMilliseconds(). A length counting months or years refuses, calendarDuration, since their length depends on a calendar that does not travel |
yes |
dateRange datetimeRange timeRange |
the wire text, start/end |
no |
condition
DateTimeType.condition(operator, operand);What a field of instants means for a calendar day. The day is that whole day in the configured zone, half-open from midnight to the next midnight, so a day across a daylight saving change is 23 or 25 hours as the calendar says. Each operator reads it in those terms: eq is the day, $ne its complement, $gte and $lt bound at its first instant, $lte and $gt at the next day’s. A data layer splices the answer into the field’s condition and pushes it to an engine as two bounds. Any other operator or operand answers undefined, so the data layer reads the operand through read instead, and no configured zone refuses noZone, since the client and the server must read one day.
Parameters
| Name | Type | Description |
|---|---|---|
| operator | string | eq, $ne, $gte, $gt, $lt or $lte |
| operand | CalendarDate | The day |
Returns
An array of operator maps whose $or is the condition, one map where one suffices, each bound a DateTime. undefined when the kind has no answer.
The subpath’s own examples run once this package and @semantic-ui/schema share a tree.