mw.widgets.datetime.DiscordianDateTimeFormatter

DateTimeFormatter for the Discordian calendar.

Provides various methods needed for formatting dates and times. This implementation implements the Discordian calendar, mainly for testing with something very different from the usual Gregorian calendar.

Being intended mainly for testing, niceties like i18n and better configurability have been omitted.

Extends

Constructor

new mw.widgets.datetime.DiscordianDateTimeFormatter(config) #

Create an instance of mw.widgets.datetime.DiscordianDateTimeFormatter.

Parameters:

Name Type Attributes Description
config Object optional

Configuration options

Source:

Properties

formats :Object.<string, string>static #

Default format specifications.

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

Type:

Source:
Default format specifications.

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}
  • Season {number} 1-5
  • Day {number|string} 1-73 or 'tib'
  • DOW {number} 0-4, or -1 on St. Tib's Day
  • Hour {number} 0-23
  • Minute {number} 0-59
  • Second {number} 0-59
  • Millisecond {number} 0-999
  • intercalary {string} '1' on St. Tib's Day

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.

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
  • ${season|#}: Season as a number
  • ${season|full}: Season as a string
  • ${day|#}: Day of the month as a number
  • ${day|0}: Day of the month as a number with leading 0
  • ${dow|full}: Day of the week as a string
  • ${hour|#}: Hour as a number
  • ${hour|0}: Hour as a number with leading 0
  • ${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(flag) → {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.