Datetime

Path: /src/type/datetime.coffee compiled to /lib/type/datetime.js

This validator will parse the given format using different technologies in nearly all common formats:

  • ISO 8601 datetimes

    '2013-02-08'
    '2013-W06-5'
    '2013-039'
    '2013-02-08 09'
    '2013-02-08T09'
    '2013-02-08 09:30'
    '2013-02-08T09:30'
    '2013-02-08 09:30:26'
    '2013-02-08T09:30:26'
    '2013-02-08 09:30:26.123'
    '2013-02-08 24:00:00.00'
    
  • ISO 8601 time only

  • ISO 8601 date only

    '2013-02-08 09'
    '2013-W06-5 09'
    '2013-039 09'
    
  • ISO 8601 with timezone

    '2013-02-08 09+07:00'
    '2013-02-08 09-0100'
    '2013-02-08 09Z'
    '2013-02-08 09:30:26.123+07:00'
    
  • natural language: ‘today’, ‘tomorrow’, ‘yesterday’, ‘last friday’

  • named dates

    '17 August 2013'
    '19 Aug 2013'
    '20 Aug. 2013'
    'Sat Aug 17 2013 18:40:39 GMT+0900 (JST)'
    
  • relative dates

    • ‘This Friday at 13:00’
    • ‘5 days ago’
  • specials: ‘now’

Parse options:

  • range - Boolean the value has to be a range consisting of two dates
  • timezone - String specify timezone if none given

Check options:

  • min - Integer the date should be after
  • max - Integer the date should be before

Format options:

  • part - String with: ‘date’, ‘time’ or ‘datetime’
  • format - String how to format result as string
  • ‘locale’ - String used for formatting
  • toTimezone - String transform date/time to the given timezone

Output formats

If not specified it is a Date object.

If format = 'unix' it will be an unix timestamp (seconds since January 1, 1970).

For all other format settings a corresponding output string will be generated. Use the aliases like ISO8601, RFC1123, RFC2822, RFC822, RFC1036 are supported and any moment.js format.

Also see the interval validator for time ranges without context.

The timezones may be ‘America/Toronto’, ‘EST’ or ‘Eastern Standard Time’ for example.

Schema Specification

Datetime is a schema definition for date values.

An object with the following keys allowed: range, timezone, part, min, max, format, toTimezone, locale, title, description, key, type, optional, default. The following entries have a specific format:

range

Date Range is a flag set to true to require a range of start and end date.

A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.

timezone

Timezone is the timezone to use if nothing given.

A text entry which is optional. All control characters will be removed.

part

Part is the part of the full date to extract.

A text entry which is optional and will be set to 'datetime' if not specified. All control characters will be removed. Only the values: ‘date’, ‘time’, ‘datetime’ are allowed.

min

Minimum Date is the oldest allowed date.

A <<>> is needed given as calendar <<>> or in natural language.

max

Maximum Date is the newest allowed date.

A <<>> is needed given as calendar <<>> or in natural language. The <<>> should be before <<>>.

format

Format is the moment() format string to use.

A text entry which is optional. All control characters will be removed.

toTimezone

To Timezone is the timezone to which to transform given dates.

A text entry which is optional. All control characters will be removed.

locale

Locale is the locale country code to use for formatting.

A text entry which is optional. All control characters will be removed. The text should match: /[1](-[A-Z]{2})?$/.

title

Title is the title used to describe the element.

A text entry which is optional. All control characters will be removed.

description

Description is the free description of the element.

A text entry which is optional. All control characters will be removed.

key

Binding to Keyname is the mapping to which key names in an object this element belongs.

A valid regular expression which is optional. It has to be one of the following types:

  • An object which has to be an instance of class RegExp.
  • A text entry in which all control characters will be removed. The text should match: /^/.?/[gim]$/.
type

Type is the type of element.

A text entry in which all control characters will be removed.

optional

Optional is a flag defining if this element is optional.

A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.

default

Default Value is the default value to use if nothing given.

A datetime is needed given as calendar datetime or in natural language.


  1. a-z ↩︎