ts-time-format/TemporalCompiler

Consumption

import TemporalCompiler from "ts-time-format/TemporalCompiler";

Default export#

Hierarchy#

Description#

T
Type to compile.

Interface of date/time-related type string compiler. Compiler defines a way to format a single component of a pattern defined as a sequence of same text characters. For example, "dd" sequence calls:

DAY_OF_MONTH_COMPILER.compile(date, 2);

Some character sequences write textual language-dependent strings. To handle such cases, context should be passed to the compiler:

const context = {
    monthShortNames: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
};
MONTH_COMPILER.compile(date, 3, context); // writes short name of a month, same as "MMM" sequence

If no context is passed, DEFAULT_TEMPORAL_CONTEXT representing English localization is being used.

Fields#

maxLength#

readonly maxLength: number

Maximum number of sequential characters supported in a pattern.

Methods#

compile#

(value: T, length: number, context: any = DEFAULT_TEMPORAL_CONTEXT): string

value
Value to compile.
length
Number of sequential characters used in a pattern.
context
Context object.
returns
Compiled string.
Compiles value to a string based on number of sequential characters specified in length and compiler-dependent context object which can be used, in particular, to specify language-specific textual strings.