Class: OraDateTimeConverter

Oracle® JavaScript Extension Toolkit (JET)
3.2.0

E87541-01

QuickNav

OraDateTimeConverter

Version:
  • 3.2.0
OraDateTimeConverter object implements date-time parsing and formatting and relative date formatting.

There are several ways to use the converter.

  • Using options defined by the ECMA 402 Specification, these would be the properties year, month, day, hour, minute, second, weekday, era, timeZone, hour12
  • Using a custom date and/or time format pattern using the 'pattern' property
  • Using the standard date, datetime and time format lengths defined by Unicode CLDR, these would include the properties formaType, dateFormat, timeFormat.

The options when specified take precendence in the following order:
1. pattern.
2. ECMA options.
3. formatType/dateFormat/timeFormat.

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

  • Allows use of any character for separators irrespective of the separator specified in the associated pattern. E.g., if pattern is set to 'y-M-d', the following values are all valid - 2013-11-16, 2013/11-16 and 2013aaa11xxx16.
  • Allows specifying 4 digit year in any position in relation to day and month. E.g., 11-2013-16 or 16-11-2013
  • Supports auto-correction of value, when month and day positions are swapped as long as the date is > 12 when working with the Gregorian calendar. E.g., if the pattern is 'y-M-d', 2013-16-11 will be auto-corrected to 2013-11-16. However if both date and month are less or equal to 12, no assumptions are made about the day or month and the value parsed against the exact pattern.
  • Supports auto-correction of value, for the short and long types of weekday and month names. So they can are used anywhere in the value. E.g., if the expected pattern is E, MMM, d, y, all these values are acceptable - Tue, Nov 26 2013 or Nov, Tue 2013 26 or 2013 Tue 26 Nov.
    NOTE: Lenient parsing of narrow era, weekday or month name is not supported because of ambiguity in choosing the right value. So we expect for narrow era, weekday or month option that values be provided either in their short or long forms. E.g., Sat, March 02, 2013.
  • Specifying the weekday is optional. E.g., if the expected pattern is E, MMM, d, y; then entering Nov 26, 2013, is automatically turned to Tuesday Nov 26, 2013. But entering an invalid weekday, i.e., if the weekday does not match the date, an exception is thrown.
  • Leniency rules apply equally no matter which option is used - pattern, ECMA options or formatType

Lenient parse can be disabled by setting the property lenientParse to "none". In which case the user input must be an exact match of the expected pattern and all the leniency described above will be disabled.

Constructor

new OraDateTimeConverter()

Properties:
Name Type Argument Description
options Object <optional>
an object literal used to provide optional information to the converter.

Properties
Name Type Argument Description
year string <optional>
allowed values are "2-digit", "numeric". When no options are set the default value of "numeric" is used.

Option Description Example
2-digit 2 digit representation of the year, padded: 00-99. 2001 => 01, 2016 => 16
numeric variable digit representation of the year depending on the value. 2010, 199

two-digit-year-start number <optional>
the 100-year period 2-digit year. During parsing, two digit years will be placed in the range two-digit-year-start to two-digit-year-start + 100 years. The default is 1950.

Example: if two-digit-year-start is 1950, 10 is parsed as 2010

Example: if two-digit-year-start is 1900, 10 is parsed as 1910

month string <optional>
specifies how the month is formatted. Allowed values are "2-digit", "numeric", "narrow", "short", "long". The last 3 values behave in the same way as for weekday, indicating the length of the string used. When no options are set the default value of "numeric" is used.

Option Description Example
2-digit 2 digit representation of the month, padded: 01-12. 1 => 01, 12 => 12
numeric variable digit representation of the month depending on the value. 1, 11
narrow narrow name of the month. J
short abbreviated name of the month. Jan
long wide name of the month. January

day string <optional>
specifies how the day is formatted. Allowed values are "2-digit", "numeric". When no options are set the default value of "numeric" is used.

Option Description Example
2-digit 2 digit representation of the day in month, padded: 01-31. 1 => 01, 27 => 27
numeric variable digit representation of the day in month depending on the value. 1, 31

hour string <optional>
specifies how the hour is formatted. Allowed values are "2-digit" or "numeric". The hour is displayed using the 12 or 24 hour clock, depending on the locale. See 'hour12' for details.

Option Description Example
2-digit 2 digit representation of the hour, padded: 01-24 depending on the locale. 1 => 01, 24 => 24
numeric variable digit representation of the day in month depending on the value. 1, 24

minute string <optional>
specifies how the minute is formatted. Allowed values are "2-digit", "numeric". Although allowed values for minute are numeric and 2-digit, minute is always displayed as 2 digits: 00-59.
second string <optional>
specifies whether the second should be displayed as "2-digit" or "numeric". Although allowed values for second are numeric and 2-digit, second is always displayed as 2 digits: 00-59.
millisecond string <optional>
specifies whether the millisecond should be displayed. Allowed value is "numeric".
weekday string <optional>
specifies how the day of the week is formatted. If absent, it is not included in the date formatting. Allowed values are "narrow", "short", "long" indicating the length of the string used.

Option Description Example
narrow narrow name of the day of week. M
short abbreviated name of the day of week. Mon
long wide name of the day of week. Monday

era string <optional>
specifies how the era is included in the formatted date. If absent, it is not included in the date formatting. Allowed values are "narrow", "short", "long". Although allowed values are narrow, short, long, we only display era in abbreviated format: BC, AD.
timeZoneName string <optional>
allowed values are "short", "long".

Option Description Example
short short name of the time zone. short: short name of the time zone: PDT, PST, EST, EDT. Note: Not all locales have translations for short time zone names, in this case we display the English short name
long short name of the time zone. Pacific Standard Time, Pacific Daylight Time.

timeZone string <optional>
The possible values of the timeZone property are valid IANA timezone IDs. If the users want to pass an offset, they can use one of the Etc/GMT timezone IDs.

Option Example
IANA ID America/Los_Angeles, Europe/Paris
Offset Etc/GMT-8. The offset is positive if the local time zone is behind UTC and negative if it is ahead. The offset range is between Etc/GMT-14 and Etc/GMT+12 (UTC-12 and UTC+14). Which means that Etc/GMT-8 is equivalent to UTC+08.

isoStrFormat string <optional>
specifies in which format the ISO string is returned. The possible values of isoStrFormat are: "offset", "zulu", "local", "auto". The default format is auto.

Option Description Example
offset time zone offset from UTC. 2016-01-05T11:30:00-08:00
zulu zulu time or UTC time. 2016-01-05T19:30:00Z
local local time, does not contain time zone offset. 2016-01-05T19:30:00
auto auto means the returned ISO string depends on the input string and options

dst string <optional>
The dst option can be used for time only values in conjunction with offset. Setting dst to true indicates the time is in DST. By default the time is interpreted as standard time. The possible values of dst are: "true" or "false". Default is "false".

Due to Daylight Saving Time, there is a possibility that a time exists twice If the time falls in the duplicate window (switching from daylight saving time to standard time). The application can disambiguate the time in the overlapping period using the dst option. Setting dst to true indicates the time is in DST. By default the time is interpreted as standard time.

Example: On November 1st, 2105 in US the time between 1 and 2 AM will be repeated. The dst option can indicate the distinction as follows. Initially the time is in DST, so dst:'true' is specified.
var options = {formatType:'datetime', dateFormat:'short', timeFormat:'medium', timeZone:'America/Los_Angeles', isoStrFormat: 'offset', dst : true};
var localeElements = oj.getLocaleElemnts();
var str= "11/1/15 1:59:59 AM";
cnv.parse(str, localeElements, options);-->2015-11-01T01:59:59-07:00

If the user does not pass the dst option, the time will be interpreted as standard time. var options = {formatType:'datetime', dateFormat:'short', timeFormat:'medium', timeZone:'America/Los_Angeles'};
var localeElements = oj.getLocaleElemnts();
var str= "11/1/15 1:59:59 AM";
cnv.parse(str, localeElements, options);-->2015-11-01T01:59:59-08:00

At 2AM, DST will be over and the clock brings back to 1AM. Then the dst option should be false or not specified. var options = {formatType:'datetime', dateFormat:'short', timeFormat:'medium', timeZone:'America/Los_Angeles', isoStrFormat: 'offset'};
var localeElements = oj.getLocaleElemnts();
var str= "11/1/15 1:00:00 AM";
cnv.parse(str, localeElements, options);-->2015-11-01T01:00:00-08:00

hour12 boolean <optional>
specifies what time notation is used for formatting the time. A true value uses the 12-hour clock and false uses the 24-hour clock (often called military time in the US). This property is undefined if the hour property is not used when formatting the date.

Option Example
true T13:10 is formatted as 1:10 PM
false T13:10 is formatted as 13:10

pattern string <optional>
a localized string pattern, where the the characters used in pattern conform to Unicode CLDR for date time formats. This will override all other options when present.
NOTE: 'pattern' is provided for backwards compatibility with existing apps that may want the convenience of specifying an explicit format mask. Setting a 'pattern' will override the default locale specific format. NOTE: The supported tokens for timezone are of 'Z', 'VV', and 'X'.

Letter Date or Time Component Examples
G, GG, GGG Era designator AD
y numeric representation of year 1, 2014
yy 2-digit representation of year 01, 14
yyyy 4-digit representation of year 0001, 2014
M Numeric representation of month in year: (1-12) 1, 12
MM 2-digit representation of month in year: (01-12) 01, 12
MMM Formatted name of the month, abbreviated Jan
MMMM Formatted name of the month, wide January
MMMMM Formatted name of the month, narrow J
LLL Stand-alone name of the month, abbreviated Jan
LLLL Stand-alone name of the month, wide January
LLLLL Stand-alone name of the month, narrow J
d Numeric representation of day in month (1-31) 1, 21
dd 2-digit representation of day in month (01-31) 01, 21
E, EE, EEE Formatted name of day in week, abbreviated Tue
EEEE Formatted name of day in week, wide Tuesday
EEEEE Formatted name of day in week, narrow T
c, cc, ccc Stand-alone name of day in week, abbreviated Tue
cccc Stand-alone name of day in week, wide Tuesday
ccccc Stand-alone name of day in week, narrow T
a am/pm marker PM
H Numeric hour in day (0-23) 1, 23
HH 2-digit hour in day (00-23) 01, 23
h Numeric hour in am/pm (1-12) 1, 12
hh 2-digit hour in day (01-12) 01, 12
k Numeric hour in day (1-24) 1, 24
kk 2-digit hour in day (1-24) 01, 24
K Numeric hour in am/pm (0-11) 1, 11
KK 2-digit hour in am/pm (0-11) 01, 11
m, mm 2-digit minute in hour (00-59) 05, 59
s, ss 2-digit second in minute (00-59) 01, 59
S Numeric Millisecond (0-999) 1, 999
SS 2-digit Millisecond (00-999) 01, 999
SSS 3-digit Millisecond (000-999) 001, 999
z, zz, zzz Abbreviated time zone name PDT, PST
zzzz Full time zone name Pacific Standard Time, Pacific Daylight Time
Z, ZZ, ZZZ Sign hours minutes -0800
X Sign hours -08
XX Sign hours minutes -0800
XXX Sign hours:minutes -08:00
VV Time zone ID Americs/Los_Angeles
formatType string <optional>
determines the 'standard' date and/or time format lengths to use. Allowed values: "date", "time", "datetime". See 'dateFormat' and 'timeFormat' options. When set a value must be specified.

Option Description Example
datetime date and time portions are displayed. September 20, 2015 12:04 PM September 20, 2015 12:05:35 PM Pacific Daylight Time
date date portion only is displayed. September 20, 2015
time time portion only is displayed. 12:05:35

dateFormat string <optional>
specifies the standard date format length to use when formatType is set to "date" or "datetime". Allowed values are : "short" (default), "medium", "long", "full".

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

timeFormat string <optional>
specifies the standard time format length to use when 'formatType' is set to "time" or "datetime". Allowed values: "short" (default), "medium", "long", "full".

Option Example
short 12:11 PM
medium 12:11:23 PM
long 12:12:19 PM PDT
full 12:12:37 PM Pacific Daylight Time

lenientParse string <optional>
The lenientParse property can be used to enable or disable leninet parsing. Allowed values: "full" (default), "none".

By default the lenient parse is enabled and the leniency rules descibed above will be used. When lenientParse is set to "none" the lenient parse is disabled and the user input must match the expected input otherwise an exception will be thrown.

Source:
Examples

Create a date time converter using no options. This uses the default value for year, month, day properties

var converter = OraDateTimeConverter.getInstance();
var localeElements;
var resolved = converter.resolvedOptions(localeElements);
// logs "day=numeric, month=numeric, year=numeric"
console.log("day=" + resolved.day + ", month=" + resolved.month + ", year=" + resolved.year);

Use a converter using the ECMA options to represent date

var options = { year:'2-digit', month: '2-digit', day: '2-digit'};
var localeElements;
var converter = OraDateTimeConverter.getInstance();
var date = "2016-04-17";
var str = converter.format(date, localeElements, options);

Converter using the 'pattern' option

var options = {pattern: 'MM-dd-yyyy'}; 
var localeElements;
var converter = OraDateTimeConverter.getInstance();
var date = "2016-04-17";
var str = converter.format(date, localeElements, options);

Converter using predefined style

var options = {formatType: 'date', dateFormat: 'medium'}; 
var localeElements;
var converter = OraDateTimeConverter.getInstance();
var date = "2016-04-17";
var str = converter.format(date, localeElements, options);

Create a date time converter using specific pattern with IANA timezone ID with isoStrFormat of offset.

var options = {pattern: 'MM/dd/yy hh:mm:ss a Z', timeZone: 'America/Los_Angeles', isoStrFormat: 'offset'};
var localeElements;
var converter = OraDateTimeConverter.getInstance();
var date = "2016-04-17T13:05:30";
var str = converter.format(date, localeElements, options);

Create a date time converter using specific pattern with Etc/GMT timezone ID with isoStrFormat of zulu.

var options = {pattern: 'MM/dd/yy hh:mm:ss a Z', timeZone: 'Etc/GMT-08:00', isoStrFormat: 'zulu'};  
var localeElements;
var converter = OraDateTimeConverter.getInstance();
var str = "01/05/16 01:01:01 AM +0800";
var obj = converter.parse(str, localeElements, options);

Disable lenient parse.

var options = {pattern: 'MM/dd/yy', lenientParse:'none'};  
var localeElements;
var converter = OraDateTimeConverter.getInstance();
var str = "14/05/16";
var obj = converter.parse(str, localeElements, options); --> RangeError: 13 is out of range.  Enter a value between 1 and 12 for month.

Methods

<static> calculateWeek(date) → {number}

Returns the current week in the year when provided a date.
Parameters:
Name Type Description
date string iso 8601 string. It may be in extended or non-extended form. http://en.wikipedia.org/wiki/ISO_8601
Source:
Returns:
. The current week in the year when provided a date.
Type
number

<static> compareISODates(isoStr1, isoStr2, localeElements) → {number}

Compares 2 ISO 8601 strings.
Parameters:
Name Type Description
isoStr1 string isoString that may be date, time or date-time and possible timezone info
isoStr2 string isoString that may be date, time or date-time and with possible timezone info
localeElements Object The instance of LocaleElements bundle
Source:
Returns:
0 if isoStr1 is equal to this isoStr2; a value less than 0 if isoStr1 is before isoStr2; and a value greater than 0 if isoStr1 is after isoStr2.
Type
number

<static> format(value, localeElements, options, locale) → {string|null}

Format a date.
Parameters:
Name Type Argument Description
value string an iso 8601 string to be formatted. It may be in extended or non-extended form. http://en.wikipedia.org/wiki/ISO_8601
localeElements Object the instance of LocaleElements bundle.
options Object <optional>
Containing the following properties:
- weekday. Allowed values: "narrow", "short", "long".
- era. Allowed values: "narrow", "short", "long".
- year. Allowed values:"2-digit", "numeric".
- month. Allowed values: "2-digit", "numeric", "narrow", "short", "long".
- day. Allowed values: "2-digit", "numeric".
- hour. Allowed values: "2-digit", "numeric".
- minute. Allowed values: "2-digit", "numeric".
- second. Allowed values: "2-digit", "numeric".
- millisecond. Allowed values: "numeric".
- timeZone. The possible values of the timeZone property are valid IANA timezone IDs. If the users want to pass an offset, they can use one of the Etc/GMT timezone IDs. yet.
- timeZoneName. allowed values are "short", "long".
- dst. is a Boolean value. Setting dst to true indicates the time is in DST. By default the time is interpreted as standard time. The possible values of dst are: "true" or "false". Default is "false".
- hour12. is 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.
- pattern. custom String pattern as defined by Unicode CLDR.
- formatType. a predefined formatting type. Allowed values: "date", "time", "datetime".
- dateFormat. optional, specifies the date format field. Allowed values: "short", "medium", "long", "full". It is only considered when formatType is present. The default value is "short".
- timeFormat. optional, specifies the time format field. Allowed values: "short", "medium", "long", "full". It is only considered when formatType is present. The default value is "short".

The order of precedence is the following:
1. pattern.
2. ECMA options.
3. formatType.
If options is ommitted, the default will be the following object:
{
year:"numeric",
month:"numeric",
day:"numeric"
};
locale string <optional>
A BCP47 compliant language tag. it is only used to extract the unicode "nu" extension key. We currently support "arab", "latn" and "thai" numbering systems. EX: locale: 'en-US-u-nu-latn'
Source:
Throws:
  • If a propery value of the options parameter is out of range.
    Type
    RangeError
  • If an Unexpected token is encountered in the pattern.
    Type
    SyntaxError
  • if the ISO string is not valid.
    Type
    invalidISOString
Returns:
formatted date.
Type
string | null

<static> formatRelative(value, localeElements, options) → {string}

Formats an ISO String as a relative date time.

Parameters:
Name Type Argument Description
value string iso 8601 string to be formatted. This value is compared with the current date on the client to arrive at the relative formatted value.
localeElements Object the instance of LocaleElements bundle.
options Object <optional>
an Object literal containing the following properties. The default options are ignored during relative formatting
formatUsing: - Specifies the relative formatting convention. Allowed values are "displayName" and "calendar". Setting value to "displayName" uses the relative display name for the instance of the dateField, and one or two past and future instances. When omitted we use the implicit rules.
dateField: - To be used in conjunction of 'displayName' value of formatUsing attribute. Allowed values are: "day", "week", "month", "year", "hour", "minute", "second".
relativeTime: - Allowed values are: "fromNow", "toNow". "fromNow" means the system's current date is the reference and "toNow" means the value attribute is the reference. Default "fromNow".
dateOnly: - A boolean value that can be used in conjunction with calendar of formatUsing attribute. When set to true date only format is used. Example: Sunday instead of Sunday at 2:30 PM. Default value is false.
timeZone: - The timeZone attribute can be used to specify the time zone of the value parameter. The system's time zone is used for the current time. If timeZone attribute is not specified, we use the system's time zone for both. The value parameter, which is an iso string, can be Z or contain and offset, in this case the timeZone attribute is overwritten.
Source:
Returns:
relative date.
Type
string
Examples

Relative time in the future using implicit rules

var localeElements;
var dateInFuture = new Date();
dateInFuture.setMinutes(dateInFuture.getMinutes() + 41);
dateInFuture = oj.OraI18nUtils.dateToLocalIso(dateInFuture);
var formatted = converter.formatRelative(dateInFuture, localeElements); -> in 41 minutes

Relative time in the past using implicit rules

var localeElements;
var dateInPast = new Date();
dateInPast.setHours(dateInPast.getHours() - 20);
dateInPast = oj.OraI18nUtils.dateToLocalIso(dateInPast);
var formatted = converter.formatRelative(dateInPast, localeElements); -> 20 hours ago

Relative time using dateField. Assuming system's current date is 2016-07-28.

Format relative year:
var localeElements;
var options = {formatUsing: "displayName", dateField: "year"};
var formatted = converter.formatRelative("2015-06-01T00:00:00", localeElements, options); -> last year

Relative time using relativeTime. Assuming system's current date is 2016-07-28.

var localeElements;
var options = {formatUsing: "displayName", dateField: "day", relativeTime: "fromNow"};
var formatted = converter.formatRelative("2016-07-28T00:00:00", localeElements, options); -> tomorrow
options = {formatUsing: "displayName", dateField: "day", relativeTime: "toNow"};
formatted = converter.formatRelative("2016-07-28T00:00:00", localeElements, options); -> yesterday

Relative time using calendar. Assuming system's current date is 2016-07-28.

var localeElements;
var options = {formatUsing: "calendar"};
var formatted = converter.formatRelative("2016-07-28T14:15:00", localeElements, options); -> tomorrow at 2:30 PM

Relative time using timeZone. Assuming that the system's time zone is America/Los_Angeles.

var localeElements;
var options = {timeZone:"America/New_York"};
var nyDateInFuture = new Date();
nyDateInFuture.setHours(nyDateInFuture.getHours() + 6);
nyDateInFuture = oj.OraI18nUtils.dateToLocalIso(nyDateInFuture);
var formatted = converter.formatRelative(nyDateInFuture, localeElements, options); -> in 3 hours

<static> getAvailableTimeZones(localeElements) → {Object}

Returns the available timeZones.
Parameters:
Name Type Description
localeElements Object The instance of LocaleElements bundle
Source:
Returns:
. An array of objects. Each object represents a timezone and contains 2 attributes:
'id': IANA timezone ID
'displayName': It is the concatenation of 3 strings:
1- UTC timezone offset.
2- City name.
3- Generic time zone name The displayName attribute is localized based on the current locale. Example of an array entry in en-US locale: {id: 'America/Edmonton',
displayName: '(UTC-07:00) Edmonton - Mountain Time'
}
The same array entry is the following in fr-FR locale: {id: 'America/Edmonton',
displayName: '(UTC-07:00) Edmonton - heure des Rocheuses'
}
The array is sorted by offsets in ascending order. Within the same offset, the entries by displayName in ascending order.
Type
Object

<static> getInstance() → {Object}

getInstance. Returns the singleton instance of OraDateTimeConverter class.
Source:
Returns:
The singleton OraDateTimeConverter instance.
Type
Object

<static> getTimePositioning(localeElements, options, locale) → {Object}

returns time tokens positions
Parameters:
Name Type Argument Description
localeElements Object the instance of LocaleElements bundle.
options Object <optional>
ECMA options or a pattern
locale string <optional>
A BCP47 compliant language tag. it is only used to extract the unicode extension keys.
Source:
Returns:
. time tokens positions. For example if the pattern is 'hh:mm a' the return value is { 'h': 0, 'm': 1, 'a': 2 }, fot RTL locales the order of the tokens is reversed for 'h' and 'm' { 'h':1, 'm': 0, 'a': 2 }
Type
Object

<static> isHour12(localeElements) → {boolean}

returns if a locale is 12 or 24 hour format.
Parameters:
Name Type Description
localeElements Object The instance of LocaleElements bundle
Since:
  • 2.2
Source:
Returns:
true if the locale's preferred hour format is 12, false for 24 hour format.
Type
boolean

<static> parse(str, localeElements, options, locale) → {string}

Parse a date. It also support lenient parse when input does not match the pattern.
We first try to match month a pattern where we have month and weekday names Ex: Monday Nov, 11 2013 weekday name and month name can be anywhere in the string. if year > 2-digits it can be anywhere in the string. Otherwise we assume its position based on pattern. Separators can be any non digit characters
If month name is not present, we try lenient parse yMd and yMEd pattern. Must have year, moth and date all numbers. Ex: 5/3/2013 weekday is optional. If present it must match date. Ex: Tuesday 11/19/2013 if year > 2-digits it can be anywhere in the string. Otherwise assume its position based on pattern if date > 12 it can be anywhere in the string. Otherwise assume its position based on pattern separators can be any non digit characters.

Parameters:
Name Type Argument Description
str string a String to be parsed. it can be an iso 8601 string or a formatted string.
localeElements Object The instance of LocaleElements bundle
options Object <optional>
Containing the following properties:
- weekday. Allowed values: "narrow", "short", "long".
- era. Allowed values: "narrow", "short", "long".
- year. Allowed values:"2-digit", "numeric".
- month. Allowed values: "2-digit", "numeric", "narrow", "short", "long".
- day. Allowed values: "2-digit", "numeric".
- hour. Allowed values: "2-digit", "numeric".
- minute. Allowed values: "2-digit", "numeric".
- second. Allowed values: "2-digit", "numeric".
- millisecond. Allowed values: "numeric".
- timeZone. The possible values of the timeZone property are valid IANA timezone IDs. If the users want to pass an offset, they can use one of the Etc/GMT timezone IDs. yet.
- timeZoneName. allowed values are "short", "long".
- dst is a Boolean value. Setting dst to true indicates the time is in DST. By default the time is interpreted as standard time. The possible values of dst are: "true" or "false". Default is "false".
-isoStrFormat.specifies in which format the ISO string is returned. The possible values of isoStrFormat are: "offset", "zulu", "local", "auto". The default format is auto.
- hour12. is 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.
- pattern. custom String pattern as defined by Unicode CLDR.
- two-digit-year-start. the 100-year period 2-digit year. During parsing, two digit years will be placed in the range two-digit-year-start to two-digit-year-start + 100 years. The default is 1950.
- formatType. a predefined formatting type. Allowed values: "date", "time", "datetime".
- dateFormat. optional, specifies the date format. Allowed values: "short", "medium", "long", "full". It is only considered when formatType is present. The default value is "short".
- timeFormat. optional, specifies the time format. Allowed values: "short", "medium", "long", "full". It is only considered when formatType is present. The default value is "short".

The order of precedence is the following:
1. pattern.
2. ECMA options.
3. formatType.
If options is ommitted, the default will be the following object:
{
year:"numeric",
month:"numeric",
day:"numeric"
};
- lenientParse. specifies if lenient parse is enabled or disabled. Allowed values: "full", "none". default is "full" which means lenient parse is enabled.
locale string <optional>
A BCP47 compliant language tag. it is only used to extract the unicode "nu" extension key. We currently support "arab", "latn" and "thai" numbering systems. EX: locale: 'en-US-u-nu-latn'
Source:
Throws:
  • If a property value of the options parameter is out of range.
    Type
    RangeError
  • If an Unexpected token is encountered in the pattern.
    Type
    SyntaxError
  • If the str parameter does not match the format pattern.
    Type
    Error
  • if one of the date fields is out of range.
    Type
    RangeError
  • if the string to be parsed is an invalid ISO string.
    Type
    invalidISOString
Returns:
an iso 8601 extended String. http://en.wikipedia.org/wiki/ISO_8601. If the patern is a date only, returns the date part of the iso string. If the pattern is time only, returns the time part of the iso string. If the pattern is date-time, returns the date-time iso string.
Example1:
var pattern = 'MM/dd/yy hh:mm:ss a';
cnv.parse('09/11/14 03:02:01 PM', localeElems, pattern);
The return value is '2014-10-20T15:02:01';
Example2:
var pattern = 'MM/dd/yy';
cnv.parse('09/11/14', localeElems, pattern);
The return value is '2014-10-20';
Example3:
var pattern = 'hh:mm:ss a';
cnv.parse('03:02:01 PM', localeElems, pattern);
The return value is 'T15:02:01';
Type
string

<static> resolvedOptions(localeElements, options, locale) → {Object}

Resolve options. Returns a new object with properties reflecting the date and time formatting options computed based on the options parameter. If the options parameter is ommitted, the following object will be returned:
{
calendar: "gregorian"
numberingSystem: "latn"
locale: <locale parameter>,
day: "numeric",
month: "numeric",
year: "numeric"
};
Parameters:
Name Type Argument Description
localeElements Object The instance of LocaleElements bundle
options Object <optional>
Containing the following properties:
- calendar. The calendar system.
- weekday. Allowed values: "narrow", "short", "long".
- era. Allowed values: "narrow", "short", "long".
- year. Allowed values:"2-digit", "numeric".
- month. Allowed values: "2-digit", "numeric", "narrow", "short", "long".
- day. Allowed values: "2-digit", "numeric".
- hour. Allowed values: "2-digit", "numeric".
- minute. Allowed values: "2-digit", "numeric".
- second. Allowed values: "2-digit", "numeric".
- millissecond. Allowed values: "numeric".
- timeZone. The possible values of the timeZone property are valid IANA timezone IDs.
- timeZoneName. allowed values are "short", "long".
- dst. is a Boolean value. The possible values of dst are: "true" or "false". Default is "false".
- isoStrFormat. specifies in which format the ISO string is returned. The possible values of isoStrFormat are: "offset", "zulu", "local", "auto". The default format is auto.
- hour12. is 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.
- pattern. custom String pattern as defined by Unicode CLDR. Will override above options when present.
- two-digit-year-start. the 100-year period 2-digit year. During parsing, two digit years will be placed in the range two-digit-year-start to two-digit-year-start + 100 years. The default is 1950.
- formatType. predefined format type. Allowed values: "datetime", "date", "time"
- dateFormat. format of date field. Allowed values: "short", "medium", "long", "full". It is only relevant when formatType is also present
- timeFormat. format of time field. Allowed values: "short", "medium", "long", "full". It is only relevant when formatType is also present
- lenientParse. specifies if lenient parse is enabled or disabled. Allowed values: "full", "none". default is "full" which means lenient parse is enabled.
locale string <optional>
A BCP47 compliant language tag. it is only used to extract the unicode extension keys.
Source:
Throws:
  • If a property value of the options parameter is out of range.
    Type
    RangeError
  • if weekday does not match the date.
    Type
    Error
Returns:
Resolved options object.
Type
Object