ts-time-format/utils

Consumption

import * as utils from "ts-time-format/utils";

parsePattern#

(pattern: string, compilers: Dictionary<TemporalCompiler<T>>): TemporalFormatComponent<T>[]

pattern
Pattern string.
compilers
Dictionary from supported pattern characters to the respective compilers.

Patterns are based on a simple sequence of characters. Pattern can be used to create formatters using their ofPattern static methods. For example:

const date = LocalDate.of(2011, DECEMBER, 3),
    formatter = DateFormatter.ofPattern("d MMM uuuu");
// equivalent to:
//  formatter = DateFormatter.of(parsePattern("d MMM uuuu", DATE_COMPILERS));
expect(formatter.format(date)).equal("3 Dec 2011");

A formatter created from a pattern can be used as many times as necessary, it is immutable.

Only characters defined in compilers are reserved as pattern characters. The count of consequent pattern characters determines the format. To write them as non-pattern characters, surround them with single quote ' symbols. All other characters don't need to be surrounded. To write a single quote, use two subsequent single quotes:

const date = LocalDate.of(2011, DECEMBER, 3),
    formatter = DateFormatter.ofPattern("'Mud'dr''");
expect(formatter.format(date)).equal("Mud3r'");