mw.widgets.datetime.ProlepticGregorianDateTimeFormatter(configopt)

Provides various methods needed for formatting dates and times. This implementation implements the proleptic Gregorian calendar over years 0000–9999.

Constructor

new mw.widgets.datetime.ProlepticGregorianDateTimeFormatter(configopt) #

A DateTimeFormatter for the proleptic Gregorian calendar.

Parameters:

Name Type Attributes Description
config Object <optional>

Configuration options

Properties
Name Type Attributes Default Description
fullMonthNames Object <optional>

Mapping 1–12 to full month names.

shortMonthNames Object <optional>

Mapping 1–12 to abbreviated month names. If fullMonthNames is given and this is not, defaults to the first three characters from that setting.

fullDayNames Object <optional>

Mapping 0–6 to full day of week names. 0 is Sunday, 6 is Saturday.

shortDayNames Object <optional>

Mapping 0–6 to abbreviated day of week names. 0 is Sunday, 6 is Saturday. If fullDayNames is given and this is not, defaults to the first three characters from that setting.

dayLetters Array.<string> <optional>

Weekday column headers for a calendar. Array of 7 strings. If fullDayNames or shortDayNames are given and this is not, defaults to the first character from shortDayNames.

hour12Periods Array.<string> <optional>

AM and PM texts. Array of 2 strings, AM and PM.

weekStartsOn number <optional>
0

What day the week starts on: 0 is Sunday, 1 is Monday, 6 is Saturday.

Source:
A DateTimeFormatter for the proleptic Gregorian calendar.

Extends

Properties

dayLetters :Array.<string>static #

Default day letters.

formats :Object.<string, string>static #

Default format specifications.

See the format parameter in mw.widgets.datetime.DateTimeFormatter.

Type:

  • Object.<string, string>
Source:
Default format specifications.

fullDayNames :Objectstatic #

Default full day of week names.

Type:

  • Object
Source:
Default full day of week names.

fullMonthNames :Objectstatic #

Default full month names.

Type:

  • Object
Source:
Default full month names.

hour12Periods :Array.<string>static #

Default AM/PM indicators.

Type:

Source:
Default AM/PM indicators.

shortDayNames :Objectstatic #

Default abbreviated day of week names.

Type:

  • Object
Source:
Default abbreviated day of week names.

shortMonthNames :Objectstatic #

Default abbreviated month names.

Type:

  • Object
Source:
Default abbreviated month names.

Methods

adjustComponent(date, component, delta, mode) → {Date} #

Adjust a date.

Parameters:

Name Type Description
date Date | null

To be adjusted

component string

To adjust

delta number

Adjustment amount

mode string

Adjustment mode:

  • 'overflow': "Jan 32" => "Feb 1", "Jan 33" => "Feb 2", "Feb 0" => "Jan 31", etc.
  • 'wrap': "Jan 32" => "Jan 1", "Jan 33" => "Jan 2", "Jan 0" => "Jan 31", etc.
  • 'clip': "Jan 32" => "Jan 31", "Feb 32" => "Feb 28" (or 29), "Feb 0" => "Feb 1", etc.
Overrides:
Source:

Returns:

Adjusted date

Type
Date
Adjust a date.

datePartIsEqual(date1, date2) → {boolean} #

Test whether the date parts of two Dates are equal.

Parameters:

Name Type Description
date1 Date
date2 Date
Inherited From:
Source:

Returns:

Type
boolean
Test whether the date parts of two Dates are equal.

formatSpecValue(v) → {string}protected #

Format a value for a field specification.

'this' must be the field specification object. The intention is that you could just assign this function as the 'formatValue' for each field spec.

Besides the publicly-documented fields, uses the following:

  • values: Enumerated values for the field
  • zeropad: Whether to pad the number with zeros.

Parameters:

Name Type Description
v any
Inherited From:
Source:

Returns:

Type
string
Format a value for a field specification.

getCalendarData(current) → {CalendarGridData} #

Get data for a calendar grid.

A "day" object is:

  • display: {string} Display text for the day.
  • date: {Date} Date to use when the day is selected.
  • extra: {string|null} 'prev' or 'next' on days used to fill out the weeks at the start and end of the month.

In any one result object, 'extra' + 'display' will always be unique.

Parameters:

Name Type Description
current Date | null

Current date

Overrides:
Source:

Returns:

Data

Type
CalendarGridData
Get data for a calendar grid.

getCalendarHeadings() → {Array} #

Get the column headings (weekday abbreviations) for a calendar grid.

Null-valued columns are hidden if getCalendarData() returns no "day" object for all days in that column.

Overrides:
Source:

Returns:

string or null

Type
Array
Get the column headings (weekday abbreviations) for a calendar grid.

getComponentsFromDate(date) → {Object} #

Get components from a Date object.

Components are:

  • year {number}
  • month {number} (1-12)
  • day {number} (1-31)
  • dow {number} (0-6, 0 is Sunday)
  • hour {number} (0-23)
  • hour12 {number} (1-12)
  • hour12period {boolean}
  • minute {number} (0-59)
  • second {number} (0-59)
  • millisecond {number} (0-999)
  • zone {number}

Parameters:

Name Type Description
date Date | null
Overrides:
Source:

Returns:

Components

Type
Object
Get components from a Date object.

getDateFromComponents(components) → {Date} #

Get a Date object from components.

Parameters:

Name Type Description
components Object

Date components

Overrides:
Source:

Returns:

Type
Date
Get a Date object from components.

getDaysInMonth(month, year) → {number}protected #

Get the number of days in a month.

Parameters:

Name Type Description
month number
year number
Source:

Returns:

Type
number
Get the number of days in a month.

getDefaultDate() → {Date} #

Get the default date.

getFieldForTag(tag, params) → {FieldSpecificationObject}protected #

Turn a tag into a field specification object.

Additional fields implemented here are:

  • ${year|#}: Year as a number
  • ${year|0}: Year as a number, zero-padded to 4 digits
  • ${month|#}: Month as a number
  • ${month|0}: Month as a number with leading 0
  • ${month|short}: Month from 'shortMonthNames' configuration setting
  • ${month|full}: Month from 'fullMonthNames' configuration setting
  • ${day|#}: Day of the month as a number
  • ${day|0}: Day of the month as a number with leading 0
  • ${dow|short}: Day of the week from 'shortDayNames' configuration setting
  • ${dow|full}: Day of the week from 'fullDayNames' configuration setting
  • ${hour|#}: Hour as a number
  • ${hour|0}: Hour as a number with leading 0
  • ${hour|12}: Hour in a 12-hour clock as a number
  • ${hour|012}: Hour in a 12-hour clock as a number, with leading 0
  • ${hour|period}: Value from 'hour12Periods' configuration setting
  • ${minute|#}: Minute as a number
  • ${minute|0}: Minute as a number with leading 0
  • ${second|#}: Second as a number
  • ${second|0}: Second as a number with leading 0
  • ${millisecond|#}: Millisecond as a number
  • ${millisecond|0}: Millisecond as a number, zero-padded to 3 digits

Parameters:

Name Type Description
tag string
params Array.<string>
Overrides:
Source:

Returns:

Field specification object, or null if the tag+params are unrecognized.

Type
FieldSpecificationObject
Turn a tag into a field specification object.

getFieldSpec() → {Array} #

Fetch the field specification array for this object.

See parseFieldSpec for details on the return value structure.

Inherited From:
Source:

Returns:

Type
Array
Fetch the field specification array for this object.

getLocal() → {boolean} #

Whether dates are in local time or UTC.

Inherited From:
Source:

Returns:

True if local time

Type
boolean
Whether dates are in local time or UTC.

localChangesDatePart(date) → {boolean} #

Test whether toggleLocal() changes the date part.

Parameters:

Name Type Description
date Date
Inherited From:
Source:

Returns:

Type
boolean
Test whether toggleLocal() changes the date part.

mergeDateAndTime(datepart, timepart) → {Date} #

Create a new Date by merging the date part from one with the time part from another.

Parameters:

Name Type Description
datepart Date
timepart Date
Inherited From:
Source:

Returns:

Type
Date

Create a new Date by merging the date part from one with the time part from another.

parseFieldSpec(format) → {Array}protected #

Parse a format string into a field specification.

The input is a string containing tags formatted as ${tag|param|param...} (for editable fields) and $!{tag|param|param...} (for non-editable fields). Most tags are defined by getFieldForTag, but a few are defined here:

  • ${intercalary|X|text}: Text that is only displayed when the 'intercalary' component is X.
  • ${not-intercalary|X|text}: Text that is displayed unless the 'intercalary' component is X.

Elements of the returned array are strings or objects. Strings are meant to be displayed as-is. Objects are as returned by getFieldForTag.

Parameters:

Name Type Description
format string
Inherited From:
Source:

Returns:

Type
Array
Parse a format string into a field specification.

parseSpecValue(v) → {number|string|null}protected #

Parse a value for a field specification.

'this' must be the field specification object. The intention is that you could just assign this function as the 'parseValue' for each field spec.

Besides the publicly-documented fields, uses the following:

  • values: Enumerated values for the field

Parameters:

Name Type Description
v string
Inherited From:
Source:

Returns:

Type
number | string | null
Parse a value for a field specification.

sameCalendarGrid(date1, date2) → {boolean} #

Test whether two dates are in the same calendar grid.

Parameters:

Name Type Description
date1 Date
date2 Date
Overrides:
Source:

Returns:

Type
boolean
Test whether two dates are in the same calendar grid.

timePartIsEqual(date1, date2) → {boolean} #

Test whether the time parts of two Dates are equal.

Parameters:

Name Type Description
date1 Date
date2 Date
Inherited From:
Source:

Returns:

Type
boolean
Test whether the time parts of two Dates are equal.

toggleLocal(flagopt) → {mw.widgets.datetime.DateTimeFormatter} #

Toggle whether dates are in local time or UTC.

Parameters:

Name Type Attributes Description
flag boolean <optional>

Set the flag instead of toggling it

Inherited From:
Source:

Fires:

Returns:

Type
mw.widgets.datetime.DateTimeFormatter
Toggle whether dates are in local time or UTC.