Class Index | File Index

Classes


Class DateFmt

Create a new date formatter instance. The date formatter is immutable once it is created, but can format as many different dates as needed with the same options. Create different date formatter instances for different purposes and then keep them cached for use later if you have more than one date to format.

The options may contain any of the following properties:

Any substring containing letters within single or double quotes will be used as-is in the final output and will not be interpretted for codes as above.

Example: a date format in Spanish might be given as: "'El' d. 'de' MMMM", where the 'El' and the 'de' are left as-is in the output because they are quoted. Typical output for this example template might be, "El 5. de Mayo". The following options will be used when formatting a date/time with an explicit template:

All other options will be ignored and their corresponding getter methods will return the empty string.


Defined in: ilib-full-dyn.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
DateFmt(options)
Method Summary
Method Attributes Method Name and Description
 
format(dateLike)
Format a particular date instance according to the settings of this formatter object.
 
formatRelative(reference, date)
Return a string that describes a date relative to the given reference date.
 
Return the name of the calendar used to format date/times for this formatter instance.
 
Return the clock option set in the constructor.
 
Return the date components that this formatter formats.
 
getDaysOfWeek(options)
Returns an array of the days of the week, formatted to the optional length specified.
 
Return the length used to format date/times in this formatter.
 
Return the locale used with this formatter instance.
<static>  
DateFmt.getMeridiemsRange(options)
Return the range of possible meridiems (times of day like "AM" or "PM") in this date formatter.
 
Return the meridiems range in current locale.
 
getMonthsOfYear(options)
Returns an array of the months of the year, formatted to the optional length specified.
 
Return the template string that is used to format date/times for this formatter instance.
 
Return the time components that this formatter formats.
 
Return the time zone used to format date/times for this formatter instance.
 
Return the type of this formatter.
 
Convert this formatter to a string representation by returning the format template.
Class Detail
DateFmt(options)
Parameters:
{Object} options
options governing the way this date formatter instance works
Method Detail
{string} format(dateLike)
Format a particular date instance according to the settings of this formatter object. The type of the date instance being formatted must correspond exactly to the calendar type with which this formatter was constructed. If the types are not compatible, this formatter will produce bogus results.
Parameters:
{IDate|Number|String|Date|JulianDay|null|undefined} dateLike
a date-like object to format
Returns:
{string} the formatted version of the given date instance

{string} formatRelative(reference, date)
Return a string that describes a date relative to the given reference date. The string returned is text that for the locale that was specified when the formatter instance was constructed.

The date can be in the future relative to the reference date or in the past, and the formatter will generate the appropriate string.

The text used to describe the relative reference depends on the length of time between the date and the reference. If the time was in the past, it will use the "ago" phrase, and in the future, it will use the "in" phrase. Examples:

Parameters:
{IDate|Number|String|Date|JulianDay|null|undefined} reference
a date that the date parameter should be relative to
{IDate|Number|String|Date|JulianDay|null|undefined} date
a date being formatted
Throws:
"Wrong calendar type" when the start or end dates are not the same calendar type as the formatter itself
Returns:
{string} the formatted relative date

{string} getCalendar()
Return the name of the calendar used to format date/times for this formatter instance.
Returns:
{string} the name of the calendar used by this formatter

{string} getClock()
Return the clock option set in the constructor. If the clock option was not given, the default from the locale is returned instead.
Returns:
{string} "12" or "24" depending on whether this formatter uses the 12-hour or 24-hour clock

{string} getDateComponents()
Return the date components that this formatter formats. This is either the value of the date option to the constructor, or the default value. If this formatter is a time-only formatter, this method will return the empty string. The date component letters may be specified in any order in the constructor, but this method will reorder the given components to a standard order.
Returns:
{string} the date components that this formatter formats

{Array} getDaysOfWeek(options)
Returns an array of the days of the week, formatted to the optional length specified. i.e. ...getDaysOfWeek() OR ...getDaysOfWeek({length: "short"})

The options parameter may contain any of the following properties:

Parameters:
{Object=} options
an object-literal that contains one key "length" with the standard length strings
Returns:
{Array} an array of all of the names of the days of the week

{string} getLength()
Return the length used to format date/times in this formatter. This is either the value of the length option to the constructor, or the default value.
Returns:
{string} the length of formats this formatter returns

{Locale} getLocale()
Return the locale used with this formatter instance.
Returns:
{Locale} the Locale instance for this formatter

<static> {Array.<{name:string|start:string|end:string}>} DateFmt.getMeridiemsRange(options)
Return the range of possible meridiems (times of day like "AM" or "PM") in this date formatter.

The options may contain any of the following properties:

Parameters:
{Object} options
options governing the way this date formatter instance works for getting meridiems range
Returns:
{Array.<{name:string|start:string|end:string}>}

{Array.<{name:string|start:string|end:string}>} getMeridiemsRange()
Return the meridiems range in current locale.
Returns:
{Array.<{name:string|start:string|end:string}>} the range of available meridiems

{Array} getMonthsOfYear(options)
Returns an array of the months of the year, formatted to the optional length specified. i.e. ...getMonthsOfYear() OR ...getMonthsOfYear({length: "short"})

The options parameter may contain any of the following properties:

Parameters:
{Object=} options
an object-literal that contains any of the above properties
Returns:
{Array} an array of the names of all of the months of the year in the current calendar

{string} getTemplate()
Return the template string that is used to format date/times for this formatter instance. This will work, even when the template property is not explicitly given in the options to the constructor. Without the template option, the constructor will build the appropriate template according to the options and use that template in the format method.
Returns:
{string} the format template for this formatter

{string} getTimeComponents()
Return the time components that this formatter formats. This is either the value of the time option to the constructor, or the default value. If this formatter is a date-only formatter, this method will return the empty string. The time component letters may be specified in any order in the constructor, but this method will reorder the given components to a standard order.
Returns:
{string} the time components that this formatter formats

getTimeZone()
Return the time zone used to format date/times for this formatter instance.
Returns:
a string naming the time zone

{string} getType()
Return the type of this formatter. The type is a string that has one of the following values: "time", "date", "datetime".
Returns:
{string} the type of the formatter

{string} toString()
Convert this formatter to a string representation by returning the format template. This method delegates to getTemplate.
Returns:
{string} the format template

Documentation generated by JsDoc Toolkit 2.4.0 on Tue Feb 02 2016 15:53:54 GMT-0800 (PST)