Caplin Trader 5.1.0

Class: module:br-parsing/DateParser

module:br-parsing/DateParser()

Matches a date string and converts it to a specified output format.

DateParser is typically used with Presenter, but can be invoked programmatically as in the following example which evaluates to "08-Sep-2000":

new DateParser().parse("09/08/2000", {american:"true", outputFormat:"d-M-Y"})

See module:br-formatting/DateFormatter for the complementary formatter.

Constructor

new module:br-parsing/DateParser()

Implements:
Deprecated:

Methods

isSingleUseParser()

Allows parsers that should only run a single time, and that should not repeatedly re-parse their own output.

This method is optional. Parsers that don't implement it are not considered to be single-use parsers by default.

Implements:

parse(vValue, mAttributes) → {string}

Matches a date string and converts it to a specified output format.

In order to match the date, either a list of explicit inputFormats can be supplied, or an american indicator can be used against a set of standard formats, which are as follows:

American: m-d-Y, m-d-y, M-d-Y, M-d-y, m-d
European: d-m-Y, d-m-Y, d-M-Y, d-M-Y, d-m

Parameters:
Name Type Description
vValue string | Date

the date to parse.

mAttributes object

the map of attributes.

Properties
Name Type Attributes Default Description
american boolean <optional>
false

if true, dates are assumed to be in American format, i.e. month before date

separators string <optional>
'/.-'

a set of admissible separator characters

inputFormats string

a comma separated list of admissible input formats

outputFormat string

the output date format

endOfUnit boolean <optional>
false

if true, parse ambiguous dates to the end of the month or year

Implements:
Returns:

the date, expressed in the output format

Type
string