Skip to main content Link Search Menu Expand Document (external link)

DateTimeFormat overview

This module implements a CVTemplate (see Template.ts) dedicated to parsing and formatting dates. It supports many of the available unicode tokens (see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table).


Table of contents


Constructors

make

Builds a DateTimeFormat from a Context context and an array of TemplatePart’s templateParts

Signature

export declare const make: ({
  context,
  templateParts
}: {
  readonly context: CVDateTimeFormatContext.Type
  readonly templateParts: ReadonlyArray<TemplatePart.Type>
}) => Type

Destructors

context

Returns the context property of self

Signature

export declare const context: MTypes.OneArgFunction<Type, CVDateTimeFormatContext.Type>

templateParts

Returns the templateParts property of self

Signature

export declare const templateParts: MTypes.OneArgFunction<Type, TemplateParts.Type>

Formatting

toFormatter

Returns a function that formats a DateTime according to ‘self’.

Signature

export declare const toFormatter: (self: Type) => Formatter.Type

toThrowingFormatter

Same as toFormatter but the returned formatter returns directly a string or throws in case of error

Signature

export declare const toThrowingFormatter: MTypes.OneArgFunction<Type, MTypes.OneArgFunction<CVDateTime.Type, string>>

Guards

has

Type guard

Signature

export declare const has: (u: unknown) => u is Type

Models

Formatter (namespace)

Namespace of a DateTimeFormat Formatter

Type (interface)

Type that describes a DateTimeFormat Formatter

Signature

export interface Type extends MTypes.OneArgFunction<CVDateTime.Type, Either.Either<string, MInputError.Type>> {}

Parser (namespace)

Namespace of a DateTimeFormat Parser

Type (interface)

Type that describes a DateTimeFormat Parser

Signature

export interface Type extends MTypes.OneArgFunction<string, Either.Either<CVDateTime.Type, MInputError.Type>> {}

TemplatePart (namespace)

Namespace for a TemplatePart

Type (type alias)

Type of a TemplatePart

Signature

export type Type = Placeholder.Type | Separator.Type

Placeholder (namespace)

Namespace for a TemplatePart that represents a part of a date time

Type (interface)

Type that represents a Placeholder

Signature

export interface Type extends MInspectable.Type, Pipeable.Pipeable {
  /** Name of this Placeholder */
  readonly name: CVDateTimeFormatContext.Token

  /** @internal */
  readonly [_TypeId]: _TypeId
}

Separator (namespace)

Namespace for a TemplatePart that represents a Separator

Type (interface)

Type that represents a SeparatorTemplatePart

Signature

export interface Type extends MInspectable.Type, Pipeable.Pipeable {
  /** The separator */
  readonly value: string

  /** @internal */
  readonly [_TypeId]: _TypeId
}

TemplateParts (namespace)

Namespace TemplateParts

Type (interface)

Type of an array of TemplatePart’s

Signature

export interface Type extends ReadonlyArray<TemplatePart.Type> {}

Type (interface)

Type that represents a DateTimeFormat.

Signature

export interface Type extends MInspectable.Type, Pipeable.Pipeable {
  /** The CVDateTimeFormatContext of this DateTimeFormat */
  readonly context: CVDateTimeFormatContext.Type

  /** The array of TemplatePart's contituting this DateTimeFormat */
  readonly templateParts: TemplateParts.Type

  /** @internal */
  readonly _template: CVTemplate.Type<CVTemplateParts.Type<CVReal.Type>>

  readonly [_TypeId]: _TypeId
}

Module markers

moduleTag

Module tag

Signature

export declare const moduleTag: "@parischap/conversions/DateTimeFormat/"

Parsing

toParser

Returns a function that parses a text into a DateTime according to ‘self’. See DateTime.fromParts for more information on default values and errors.

Signature

export declare const toParser: (self: Type) => Parser.Type

toThrowingParser

Same as toParser but the returned parser returns directly a CVDateTime or throws in case of failure

Signature

export declare const toThrowingParser: MTypes.OneArgFunction<Type, MTypes.OneArgFunction<string, CVDateTime.Type>>