Final Class: LocalDateConverter

Oracle® JavaScript Extension Toolkit (JET)


  • 15.0.0
  • ojconverter-localdate



Constructs an immutable instance and initializes it with the options provided. When initialized with no options, the default options for the current locale are assumed. When the locale is not provided, the converter will be calling Config.getLocale() to determine the current JET page locale. When constructed with invalid options, an error is thrown. The behavior of the converter may be customized by using the standard date format lengths defined by Unicode CLDR using the dateStyle option, e.g., 'short', 'medium', 'long', 'full'.

The converter provides leniency when parsing the user input value to a date iso string in the following ways:

  • Allows use of any character for separators irrespective of the locale's separator. E.g., the following values are all valid - 2013-11-16, 2013/11-16 and 2013aaa11xxx16.
  • Allows specifying a 4-digit year in any position in relation to the day and month. E.g., 11-2013-16 or 16-11-2013
  • Supports auto-correction of the value when month and day positions are swapped as long as the day is > 12 when working with the Gregorian calendar. E.g., 2013-16-11 will be auto-corrected to 2013-11-16. However, if both the day and month are less than or equal to 12, no assumptions are made about the day or month and the value is parsed against the exact pattern.
  • Supports auto-correction of the value, for the short and long types of weekday and month names so they can be used anywhere in the value. E.g., all these values are acceptable - Tue, Nov 26 2013 or Nov, Tue 2013 26 or 2013 Tue 26 Nov.
  • Specifying the weekday is optional. E.g., if the dateStyle shows the weekday, then entering Nov 26, 2013, is automatically turned into Tuesday Nov 26, 2013. But entering an invalid weekday, i.e., if the weekday does not match the date, an exception is thrown.

Note that parsing errors may still be thrown when the parsing is lenient. For example, specifying a value like 'foo' will produce an error. Lenient parse cannot be disabled.



final class LocalDateConverter

Typescript Import Format
//To import this class, use the format below.
import {LocalDateConverter} from "ojs/ojconverter-localdate";

For additional information visit:

Final classes in JET

Classes in JET are generally final and do not support subclassing. At the moment, final is not enforced. However, this will likely change in an upcoming JET release.


new LocalDateConverter(options)

Name Type Argument Description
options LocalDateConverter.ConverterOptions <optional>
an object literal used to provide optional information to initialize the converter.


format(value) : {string}

Formats a date-only iso string and returns the formatted string, using the options this converter was initialized with.
Name Type Description
value LocalDateConverter.DateISOStr to be formatted for display
an error when formatting fails, or if called with '', null, or undefined.

the localized and formatted value suitable for display.


parse(input) : {LocalDateConverter.DateISOStr}

Parses a string value to return a date-only iso string, using the options this converter was initialized with.
Name Type Description
input string to parse to a date-only iso string.
a translated error when parsing fails, or if this method is called with '', null, or undefined. Parsing errors are user input errors. Parsing error messages are shown to the user which is why they are translated.

the parsed string as a date iso string., e.g., 2023-03-31


resolvedOptions : {LocalDateConverter.ConverterOptions}

Returns an object literal with properties reflecting the date formatting options computed based on the options parameter. If an option is not provided, the properties will be derived from the locale defaults.
an error when the options that the converter was initialized with are invalid.

An object literal containing the resolved options.


Type Definitions


A string with a BCP 47 language tag, for example, 'en-US'.


Name Type Argument Description
dateStyle 'short' | 'medium' | 'long' | 'full' <optional>
specifies the standard date format length to use. Allowed values are : "short" (default), "medium", "long", "full". When no options are specified, the default is dateStyle short. dateStyle short will always have a numeric year by default for JET apps.

Option Example
short 9/20/2015
medium Sep 20, 2015
long September 20, 2015
full Sunday, September 20, 2015

locale BCP47Locale <optional>
specifies a locale to be used by this converter instance. If this option is not provided, the converter will be calling Config.getLocale() to determine the current JET page locale.


An iso string that has the date only. E.g., 2023-03-31