Class Index | File Index

Classes


Class DateRngFmt

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

The options may contain any of the following properties:


Defined in: DateRngFmt.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
DateRngFmt(options)
Method Summary
Method Attributes Method Name and Description
 
format(startDateLike, endDateLike)
Format a date/time range according to the settings of the current formatter.
 
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 length used to format date/times in this formatter.
 
Return the locale used with this formatter instance.
 
Return the time zone used to format date/times for this formatter instance.
Class Detail
DateRngFmt(options)
Parameters:
{Object} options
options governing the way this date range formatter instance works
Method Detail
{string} format(startDateLike, endDateLike)
Format a date/time range according to the settings of the current formatter. The range is specified as being from the "start" date until the "end" date.

The template that the date/time range uses depends on the length of time between the dates, on the premise that a long date range which is too specific is not useful. For example, when giving the dates of the 100 Years War, in most situations it would be more appropriate to format the range as "1337 - 1453" than to format it as "10:37am November 9, 1337 - 4:37pm July 17, 1453", as the latter format is much too specific given the length of time that the range represents. If a very specific, but long, date range really is needed, the caller should format two specific dates separately and put them together as you might with other normal strings.

The format used for a date range contains the following date components, where the order of those components is rearranged and the component values are translated according to each locale:

In general, if any of the date components share a value between the start and end date, that component is only given once. For example, if the range is from November 15, 2011 to November 26, 2011, the start and end dates both share the same month and year. The range would then be formatted as "November 15-26, 2011".

If you want to format a length of time instead of a particular range of time (for example, the length of an event rather than the specific start time and end time of that event), then use a duration formatter instance (DurationFmt) instead. The formatRange method will make sure that each component of the date/time is within the normal range for that component. For example, the minutes will always be between 0 and 59, no matter what is specified in the date to format, because that is the normal range for minutes. A duration format will allow the number of minutes to exceed 59. For example, if you were displaying the length of a movie that is 198 minutes long, the minutes component of a duration could be 198.

Parameters:
{IDate|Date|number|string} startDateLike
the starting date/time of the range. The date may be given as an ilib IDate object, a javascript intrinsic Date object, a unix time, or a date string parsable by the javscript Date.
{IDate|Date|number|string} endDateLike
the ending date/time of the range. The date may be given as an ilib IDate object, a javascript intrinsic Date object, a unix time, or a date string parsable by the javscript Date.
Throws:
"Wrong calendar type" when the start or end dates are not the same calendar type as the formatter itself
Returns:
{string} a date range formatted for the locale

{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} 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

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

Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 15 2018 17:45:08 GMT-0800 (PST)