Constructor
new IntlDateTimeConverter()
- Source:
Properties:
Name | Type | Argument | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
an object literal used to provide an optional information to
initialize the converter.
Properties
|
Examples
Create a date time converter using no options. This uses the default value for year, month, day properties
var converterFactory = oj.Validation.converterFactory("datetime");
converter = converterFactory.createConverter();
var resolved = converter.resolvedOpions();
// logs "day=numeric, month=numeric, year=numeric"
window.console.log("day=" + resolved.day + ", month=" + resolved.month + ", year=" + resolved.year);
Create a date time converter using the ECMA options to represent date
var options = { year:'2-digit', month: '2-digit', day: '2-digit'};
var converterFactory = oj.Validation.converterFactory("datetime");
converter = converterFactory.createConverter(options);
Create a date time converter using the 'pattern' option
var options = {pattern: 'MM-dd-yyyy'};
var converterFactory = oj.Validation.converterFactory("datetime");
converter = converterFactory.createConverter(options);
Create a date time converter using the standard format length
var options = {formatType: 'date', dateFormat: 'medium'};
var converterFactory = oj.Validation.converterFactory("datetime");
converter = converterFactory.createConverter(options);
Methods
-
format(value) → {string}
-
Formats the Date value using the resolved options and returns a String value.
Parameters:
Name Type Description value
Date to be formatted for display - Source:
- ojvalidation/IntlDateTimeConverter.js, line 167
Throws:
a ConverterError both when formatting fails, and if the options provided during initialization cannot be resolved correctly.- Type
- Error
Returns:
the localized and formatted value suitable for display- Type
- string
-
formatRelative(value, relativeOptions) → {string|null}
-
Formats a Date object as a relative date, using the relativeOptions.
Parameters:
Name Type Description value
Date Date object to be formatted. This value is compared with the current date on the client to arrive at the relative formatted value. relativeOptions
Object an Object literal containing the following properties. The default options are ignored during relative formatting -
- formatUsing: Specifies the relative formatting convention to use for (calendar or)
the date field type. allowed values: "displayName".
Setting value to 'displayName' uses the relative display name for the instance of the dateField, and one or two past and future instances. - dateField: allowed values are: "day", "week", "month", "year"
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 211
Throws:
an instance of oj.ConverterError- Type
- Object
Returns:
relative date. null if the value falls out side the supported relative range.- Type
- string | null
- formatUsing: Specifies the relative formatting convention to use for (calendar or)
the date field type. allowed values: "displayName".
-
getHint() → {String}
-
Retrieves a hint String describing the format the value is expected to be in.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 231
Returns:
a hint describing the format the value is expected to be in.- Type
- String
-
getOptions() → {Object}
-
Returns the options called with converter initialization.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 271
Returns:
an object of options.- Type
- Object
-
Init(options)
-
Initializes the date time converter instance with the set options.
Parameters:
Name Type Argument Description options
Object <optional>
an object literal used to provide an optional information to initialize the converter. - Source:
- ojvalidation/IntlDateTimeConverter.js, line 140
-
isDayNameSet()
-
Returns true if the day name is shown in the date portion; false otherwise.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 419
-
isDaySet()
-
Returns true if day is shown in the date portion; false otherwise.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 410
-
isHourInAMPMSet()
-
Returns true if 12-hour is set; false otherwise.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 348
-
isHourInDaySet()
-
Returns true if a 24-hour format is set; false otherwise.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 332
-
isMilliSecondSet()
-
Returns true if milliseconds are shown in the time portion; false otherwise.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 383
-
isMinuteSet()
-
Returns true if minutes are shown in the time portion; false otherwise.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 365
-
isMonthSet()
-
Returns true if month is shown in the date portion; false otherwise.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 401
-
isSecondSet()
-
Returns true if seconds are shown in the time portion; false otherwise.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 374
-
isYearSet()
-
Returns true if year is shown in the date portion; false otherwise.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 392
-
parse(value) → {Date}
-
Parses the value using the resolved options provided and returns a Date value.
Parameters:
Name Type Description value
String | string to parse - Source:
- ojvalidation/IntlDateTimeConverter.js, line 435
Throws:
a ConverterError both when parsing fails, and if the options provided during initialization cannot be resolved correctly.- Type
- Error
Returns:
the parsed value as a Date object.- Type
- Date
-
resolvedOptions() → {Object}
-
Returns an object literal with locale and formatting options computed during initialization of the object. If options was not provided at the time of initialization, the properties will be derived from the locale defaults.
- Source:
- ojvalidation/IntlDateTimeConverter.js, line 303
Throws:
a oj.ConverterError when the options that the converter was initialized with are invalid.Returns:
an object of resolved options. Properties whose corresponding internal properties are not present are not assigned. More properties may be included as needed.- locale - a String value with the language tag of the locale whose localization is used for formatting.
- numberingSystem: a String value of the numbering system used. E.g. latn
- era: a String value. One of allowed values - "narrow", "short", "long"
- year: a String value. One of allowed values - "2-digit", "numeric"
- month: a String value. One of allowed values - "2-digit", "numeric", "narrow", "short" , "long"
- weekday: a String value. One of the allowed values - "narrow", "short", "long"
- day: a String value. One of allowed values - "2-digit", "numeric"
- hour: String value. One of allowed values - "2-digit", "numeric"
- minute: a String value. One of allowed values - "2-digit", "numeric"
- second: a String value. One of allowed values - "2-digit", "numeric"
- hour12: a Boolean value indicating whether 12-hour format (true) or 24-hour format (false) should be used. It is only relevant when hour is also present.
- timeZoneName: String value. One of allowed values - "short", "long".
- Type
- Object