Constructor
new mw.widgets.datetime.DateTimeFormatter([config])abstract
#
Create an instance of mw.widgets.datetime.DateTimeFormatter
.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object |
optional |
Configuration options Properties:
|
- Mixes in:
- Source:
Properties
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:
|
Returns:
Adjusted date
- Type
- Date
datePartIsEqual(date1, date2) → {boolean}
#
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 |
Returns:
- Type
- string
getCalendarData(current) → {CalendarGridData}abstract
#
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 |
Returns:
Data
- Type
- CalendarGridData
getCalendarHeadings() → {Array}abstract
#
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.
Returns:
string or null
- Type
- Array
getComponentsFromDate(date) → {Object}abstract
#
Get components from a Date object.
Most specific components are defined by the subclass. "Global" components are:
- intercalary: {string} Non-falsey values are used to indicate intercalary days.
- zone: {number} Timezone offset in minutes.
Parameters:
Name | Type | Description |
---|---|---|
date |
Date
|
null
|
Returns:
Components
- Type
- Object
getDateFromComponents(components) → {Date}
#
getFieldForTag(tag, params) → {FieldSpecificationObject}abstractprotected
#
Turn a tag into a field specification object.
Fields implemented here are:
- ${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.
- ${zone|#}: Timezone offset, "+0000" format.
- ${zone|:}: Timezone offset, "+00:00" format.
- ${zone|short}: Timezone from 'shortZones' configuration setting.
- ${zone|full}: Timezone from 'fullZones' configuration setting.
Parameters:
Returns:
Field specification object, or null if the tag+params are unrecognized.
getFieldSpec() → {Array}
#
Fetch the field specification array for this object.
See parseFieldSpec
for details on the return value structure.
Returns:
- Type
- Array
getLocal() → {boolean}
#
localChangesDatePart(date) → {boolean}
#
mergeDateAndTime(datepart, timepart) → {Date}
#
Create a new Date by merging the date part from one with the time part from another.
Parameters:
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 |
Returns:
- Type
- Array
parseSpecValue(v) → {number|string|null
}protected
#
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 |
Returns:
sameCalendarGrid(date1, date2) → {boolean}abstract
#
timePartIsEqual(date1, date2) → {boolean}
#
toggleLocal([flag]) → {mw.widgets.datetime.DateTimeFormatter}chainable
#
Toggle whether dates are in local time or UTC.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
flag |
boolean |
optional |
Set the flag instead of toggling it |
Returns:
Fires:
Type Definitions
CalendarGridData
#
Type:
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
header |
string | String to display as the calendar header |
|
monthComponent |
string | Component to adjust by ±1 to change months. |
|
dayComponent |
string | Component to adjust by ±1 to change days. |
|
weekComponent |
string |
optional |
Component to adjust by ±1 to change weeks. If omitted, the dayComponent should be adjusted by ±the number of non-nullable columns returned by this.getCalendarHeadings() to change weeks. |
rows |
Array | Array of arrays of "day" objects or null/undefined. |
FieldSpecificationObject
#
Type:
Properties:
Name | Type | Description |
---|---|---|
component |
string
|
null
|
Date component corresponding to this field, if any. |
editable |
boolean | Whether this field is editable. |
type |
string | What kind of field this is:
|
calendarComponent |
boolean | Whether this field is part of a calendar, e.g. part of the date instead of the time. |
size |
number | Maximum number of characters in the field (when the 'intercalary' component is falsey). If 0, the field should be hidden entirely. |
intercalarySize |
Object.<string, number> | Map from 'intercalary' component values to overridden sizes. |
value |
string | For type='static', the string to display. |
formatValue |
function | A function to format a component value as a display string. |
parseValue |
function | A function to parse a display string into a component value. If parsing fails, returns undefined. |