Skip to content
KeystoneJS LogoKeystoneJS (α)

DateTime

Usage

const { DateTime } = require('@keystone-alpha/fields');

keystone.createList('User', {
  fields: {
    lastOnline: {
      type: DateTime,
      format: 'MM/DD/YYYY h:mm A',
      yearRangeFrom: 1901,
      yearRangeTo: 2018,
      yearPickerType: 'auto',
    },
  },
});

Config

OptionTypeDefaultDescription
formatString--Defines the format of string that the component generates
yearRangeFromStringThe current year - 100Defines the starting point of the year range, eg 1918
yearRangeToStringThe current yearDefines the ending point of the range in the yearSelect field , e.g 2018
yearPickerTypeStringautoDefines the input type for the year selector
isRequiredBooleanfalseDoes this field require a value?
isUniqueBooleanfalseAdds a unique index that allows only unique values to be stored

format

Defines the format of string that the component generates. For example, MM/DD/YYYY h:mm A.

yearRangeFrom

The DateTime component includes an input that allows the user to change the current year from a range of options. This prop allows the user to set the beginning of that range.

The default value for this field is 100 years before the current year.

yearRangeTo

The DateTime component includes an input that allows the user to change the current year from a range of options. This prop allows the user to set the end of that range.

The default value for this field is the current year.

yearPickerType

The DateTime component includes an input that allows the user to change the current year from a range of options. This prop allows the user to change the type of that input.

OptionDescription
inputGenerates an input that allows the user to type in a value
selectGenerates a drop-down menu that allows the user to select a value from a list
autoWill generate a select if the range is 50 or less, otherwise will generate an input

GraphQL

The DateTime field type adds a custom scalar DateTime and uses it for input and output fields.

Storage

Mongoose Adaptor

On the Mongoose adapter the DateTime value are stored across three fields:

Field nameSchema typeDescription
${path}StringThe full timestamp with offset as a ISO8601 string
${path}_utcDateThe timestamp in as a native JS-style epoch
${path}_offsetStringThe offset component as string

The isRequired config option is enforces by Keystone only.

Knex Adaptor

On the Knex adapter the DateTime value are stored across two fields:

Column nameKnex typeDescription
${path}_utctimestampThe timestamp in UTC
${path}_offsettextThe offset component as string

The isRequired config option is enforces by Keystone and, if equal to true, the column is set as not nullable.

Have you found a mistake, something that is missing, or could be improved on this page? Please edit the Markdown file on GitHub and submit a PR with your changes.

Edit Page