Time and date formatter class.
The main aim of this class is to make it easy to produce a date which is consistent with the way server-side MediaWiki formats dates, in the current user's timezone and preferred format.
The input format is always a native Date object. This isn't a date parser class.
The most common operations are available as static methods, which have no dependency on "this", so they can be called via destructuring assignment.
The constructor is internal. Instances should be obtained via the static factory methods.
Example
// Static interface
const { formatTimeAndDate } = require( 'mediawiki.DateFormatter' );
const now = formatTimeAndDate( new Date() );
// Non-static interface
const DateFormatter = require( 'mediawiki.DateFormatter' );
const mwTimestamp = DateFormatter.forUtc().formatMw( new Date() );
Methods
formatDate(date) → {string}
#
formatDateRange(date1, date2) → {string}
#
Format a date range, showing date only. (non-static)
TODO: Have MW provide localisation.
Parameters:
Returns:
- Type
- string
formatForDateTimeInput(date) → {string}
#
Format a Date in ISO 8601 format, without the timezone designator, implying unqualified local time, and without seconds.
formatIso(date) → {string}
#
formatMw(date) → {string}
#
formatPrettyDate(date) → {string}
#
formatTime(date) → {string}
#
formatTimeAndDate(date) → {string}
#
formatTimeAndDateRange(date1, date2) → {string}
#
Format a date range, showing time and date. (non-static)
TODO: Have MW provide localisation. This function depends on the browser for localisation. It does not properly respect the user's date format preferences, and has limited language support.
Parameters:
Returns:
- Type
- string
formatTimeRange(date1, date2) → {string}
#
Format a date range, showing time only. (non-static)
TODO: Have MW provide localisation.
Parameters:
Returns:
- Type
- string
getShortZoneName(date) → {string}
#
getZoneOffsetMinutes(date) → {number}
#
Get the time zone offset as a number of minutes, in the sign-preserving convention, e.g.
forSiteZone() → {module:mediawiki.DateFormatter}static
#
Get a DateFormatter instance, configured for the current user except with the site default time zone.
Returns:
Get a DateFormatter instance, configured for the current user except with the site default time zone.
forUser() → {module:mediawiki.DateFormatter}static
#
Get a DateFormatter instance configured for the current user
Returns:
forUtc() → {module:mediawiki.DateFormatter}static
#
Get a DateFormatter instance, configured for the current user except with the time zone set to UTC.
Returns:
Get a DateFormatter instance, configured for the current user except with the time zone set to UTC.
formatDate(date) → {string}static
#
formatDateRange(date1, date2) → {string}static
#
Format a date range, showing date only. (static variant)
TODO: Have MW provide localisation.
Parameters:
Returns:
- Type
- string
formatForDateTimeInput(date) → {string}static
#
Format a Date in ISO 8601 format, without the timezone designator, implying unqualified local time, and without seconds.
formatIso(date) → {string}static
#
formatPrettyDate(date) → {string}static
#
formatTime(date) → {string}static
#
formatTimeAndDate(date) → {string}static
#
formatTimeAndDateRange(date1, date2) → {string}static
#
Format a date range, showing time and date. (static variant)
TODO: Have MW provide localisation. This function depends on the browser for localisation. It does not properly respect the user's date format preferences, and has limited language support.
Parameters:
Returns:
- Type
- string
formatTimeRange(date1, date2) → {string}static
#
Format a date range, showing time only. (static variant)
TODO: Have MW provide localisation.
Parameters:
Returns:
- Type
- string
getShortZoneName(date) → {string}static
#
getZoneOffsetMinutes(date) → {number}static
#
Get the time zone offset as a number of minutes, in the sign-preserving convention, e.g.