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