Final Class: LocalDateConverter

Oracle® JavaScript Extension Toolkit (JET)
16.0.0

F83701-01

Since:
  • 15.0.0
Module:
  • ojconverter-localdate

QuickNav

Description

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.


Usage

Signature:

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.


Constructor

new LocalDateConverter(options)

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

Methods

format(value) : {string}

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

the localized and formatted value suitable for display.

Type
string

parse(input) : {LocalDateConverter.DateISOStr}

Parses a string value to return a date-only iso string, using the options this converter was initialized with.
Parameters:
Name Type Description
input string to parse to a date-only iso string.
Throws:
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.
Type
Error
Returns:

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

Type
LocalDateConverter.DateISOStr

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.
See:
Throws:
an error when the options that the converter was initialized with are invalid.
Type
Error
Returns:

An object literal containing the resolved options.

Type
LocalDateConverter.ConverterOptions

Type Definitions

BCP47Locale

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

ConverterOptions

Properties:
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.

DateISOStr

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