Ivandt logo

Date Field

Date input with automatic parsing and formatting using Moment.js

The date field provides automatic date parsing and formatting using Moment.js. The SDK handles multiple date formats and converts them to your desired output format.

Basic Usage

{
  type: 'date',
  label: 'Birth Date',
  key: 'birthDate',
  order: 0,
  formatPattern: 'YYYY-MM-DD'
}

Properties

Required

  • formatPattern (string) - Moment.js format pattern for display output

Optional

  • parsePatterns (string[]) - Array of Moment.js patterns to try when parsing input
  • strictParsing (boolean) - Use strict parsing mode (default: true)
  • yearRange ([Date, Date]) - Year range for the year dropdown (default: [1900, now])
  • defaultValue (Date | string) - Default date value

Plus all common field properties.

Automatic Behavior

The SDK automatically:

  • Adds a FormatDates transformer that runs on load and cell changes
  • Adds a date validator if not present
  • Uses [formatPattern, moment.ISO_8601] as default parsePatterns if not specified

Format Patterns

Common Moment.js format patterns:

  • 'YYYY-MM-DD' → 2025-01-15
  • 'DD/MM/YYYY' → 15/01/2025
  • 'MM/DD/YYYY' → 01/15/2025
  • 'MMMM D, YYYY' → January 15, 2025
  • 'DD-MMM-YYYY' → 15-Jan-2025

See Moment.js format documentation for all tokens.

Parsing Modes

{
  type: 'date',
  label: 'Order Date',
  key: 'orderDate',
  order: 0,
  formatPattern: 'YYYY-MM-DD',
  parsePatterns: ['YYYY-MM-DD', 'DD/MM/YYYY', 'MM-DD-YYYY'],
  strictParsing: true
}

Strict parsing requires exact format matches, avoiding ambiguous dates like "01/02/03".

Forgiving Parsing

{
  type: 'date',
  label: 'Event Date',
  key: 'eventDate',
  order: 0,
  formatPattern: 'YYYY-MM-DD',
  strictParsing: false
}

Forgiving mode attempts to parse dates even if they don't exactly match the pattern.

Use Cases

  • Birth dates, hire dates, event dates
  • Order dates, invoice dates
  • Expiry dates, deadlines
  • Any date-based data

Example

import type { IvtSchema } from '@ivandt/importer';

const schema: IvtSchema = {
  title: 'Employee Import',
  publicKey: 'pk_live_xxx',
  sessionToken: 'session_xxx',
  fields: [
    {
      type: 'date',
      label: 'Hire Date',
      key: 'hireDate',
      order: 0,
      formatPattern: 'YYYY-MM-DD',
      parsePatterns: [
        'YYYY-MM-DD',
        'DD/MM/YYYY',
        'MM/DD/YYYY',
        'YYYY/MM/DD'
      ],
      strictParsing: true,
      validators: [
        { type: 'required' }
      ]
    },
    {
      type: 'date',
      label: 'Birth Date',
      key: 'birthDate',
      order: 1,
      formatPattern: 'DD/MM/YYYY',
      parsePatterns: ['DD/MM/YYYY', 'DD-MM-YYYY'],
      yearRange: [new Date(1940, 0, 1), new Date(2010, 11, 31)]
    }
  ]
};

Multiple Input Formats

Handle various date formats from different sources:

{
  type: 'date',
  label: 'Transaction Date',
  key: 'transactionDate',
  order: 0,
  formatPattern: 'YYYY-MM-DD',
  parsePatterns: [
    'YYYY-MM-DD',      // ISO format
    'DD/MM/YYYY',      // European
    'MM/DD/YYYY',      // US
    'DD-MM-YYYY',      // Dash separated
    'YYYY/MM/DD',      // Slash separated
    'MMMM D, YYYY'     // Long format
  ],
  strictParsing: true
}

The SDK tries each pattern in order until one successfully parses the date.