Aphex
Schema Types

Datetime

Combined date and time input with UTC storage.

The datetime type stores date and time values. It renders a text input with a calendar picker and a time input. Values are always stored in UTC (YYYY-MM-DDTHH:mm:ssZ) and converted to the display format for the user.

Definition

import type { DateTimeField } from '@aphexcms/cms-core';
{
  name: 'publishedAt',
  type: 'datetime',
  title: 'Published At',
  validation: (Rule) => Rule.required()
}

Properties

PropertyTypeRequiredDescription
namestringYesField identifier.
type'datetime'YesMust be 'datetime'.
titlestringYesLabel shown in the admin UI.
descriptionstringNoHelp text shown below the label.
optionsobjectNoDisplay options. See Options.
initialValuestring | () => string | Promise<string>NoDefault value in UTC ISO format.
validation(Rule) => RuleNoValidation rules.

Options

OptionTypeDefaultUsedDescription
dateFormatstring'YYYY-MM-DD'YesDisplay format for the date portion.
timeFormatstring'HH:mm'YesDisplay format for the time portion.
timeStepnumber15Not yetDefined in the type but not yet used by the component.
allowTimeZoneSwitchbooleantrueNot yetDefined in the type but not yet used by the component.
displayTimeZonestring-Not yetDefined in the type but not yet used by the component.

The calendar popover includes a time input and a "Set to now" button that populates the current date and time.

Examples

Default datetime

{
  name: 'createdAt',
  type: 'datetime',
  title: 'Created At'
}

Custom format

{
  name: 'eventStart',
  type: 'datetime',
  title: 'Event Start',
  options: {
    dateFormat: 'DD/MM/YYYY',
    timeFormat: 'HH:mm'
  }
}

Set to current time

{
  name: 'timestamp',
  type: 'datetime',
  title: 'Timestamp',
  initialValue: () => new Date().toISOString()
}

Validation

Available rules: required(), custom(fn), error(msg), warning(msg), info(msg)

Edit on GitHub

Last updated on