UNPKG

mwn

Version:

JavaScript & TypeScript MediaWiki bot framework for Node.js

122 lines (121 loc) 4.53 kB
import type { Mwn } from './bot'; /** * Wrapper around the native JS Date() for ease of * handling dates, as well as a constructor that * can parse MediaWiki dating formats. */ export interface MwnDate extends Date { isValid(): boolean; isBefore(date: Date | MwnDate): boolean; isAfter(date: Date | MwnDate): boolean; getUTCMonthName(): string; getUTCMonthNameAbbrev(): string; getMonthName(): string; getMonthNameAbbrev(): string; getUTCDayName(): string; getUTCDayNameAbbrev(): string; getDayName(): string; getDayNameAbbrev(): string; /** * Add a given number of minutes, hours, days, months or years to the date. * This is done in-place. The modified date object is also returned, allowing chaining. * @param {number} number - should be an integer * @param {string} unit * @throws {Error} if invalid or unsupported unit is given * @returns {MwnDate} */ add(number: number, unit: timeUnit): MwnDate; /** * Subtracts a given number of minutes, hours, days, months or years to the date. * This is done in-place. The modified date object is also returned, allowing chaining. * @param {number} number - should be an integer * @param {string} unit * @throws {Error} if invalid or unsupported unit is given * @returns {MwnDate} */ subtract(number: number, unit: timeUnit): MwnDate; /** * Formats the date into a string per the given format string. * Replacement syntax is a subset of that in moment.js: * * | Syntax | Output | * |--------|--------| * | H | Hours (24-hour) | * | HH | Hours (24-hour, padded to 2 digits) | * | h | Hours (12-hour) | * | hh | Hours (12-hour, padded to 2 digits) | * | A | AM or PM | * | m | Minutes | * | mm | Minutes (padded to 2 digits) | * | s | Seconds | * | ss | Seconds (padded to 2 digits) | * | d | Day number of the week (Sun=0) | * | ddd | Abbreviated day name | * | dddd | Full day name | * | D | Date | * | DD | Date (padded to 2 digits) | * | M | Month number (1-indexed) | * | MM | Month number (1-indexed, padded to 2 digits) | * | MMM | Abbreviated month name | * | MMMM | Full month name | * | Y | Year | * | YY | Final two digits of year (20 for 2020, 42 for 1942) | * | YYYY | Year (same as `Y`) | * * @param {string} formatstr * @param {(string|number)} [zone=utc] - 'system' (for system-default time zone), * 'utc' (for UTC), or specify a time zone as number of minutes past UTC. * @returns {string} */ format(formatstr: string, zone?: number | 'utc' | 'system'): string; /** * Gives a readable relative time string such as "Yesterday at 6:43 PM" or "Last Thursday at 11:45 AM". * Similar to calendar in moment.js, but with time zone support. * @param {(string|number)} [zone=system] - 'system' (for browser-default time zone), * 'utc' (for UTC), or specify a time zone as number of minutes past UTC * @returns {string} */ calendar(zone?: number | 'utc' | 'system'): string; } export interface MwnDateStatic { /** * Create a date object. MediaWiki timestamp format is also acceptable, * in addition to everything that JS Date() accepts. */ new (...args: any[]): MwnDate; /** * Get month name from month number (1-indexed) */ getMonthName(monthNum: number): string; /** * Get abbreviated month name from month number (1-indexed) */ getMonthNameAbbrev(monthNum: number): string; /** * Get day name from day number (1-indexed, starting from Sunday) */ getDayName(dayNum: number): string; /** * Get abbreviated day name from day number (1-indexed, starting from Sunday) */ getDayNameAbbrev(dayNum: number): string; localeData: any; /** * Customize language used for day and month names. This fetches * the data from MediaWiki API. By default, it is English. * @param lang - Defaults to the content language of the wiki the bot * is logged into. */ populateLocaleData(lang?: string): Promise<void>; } export default function (bot: Mwn): MwnDateStatic; declare const unitMap: { seconds: string; minutes: string; hours: string; days: string; months: string; years: string; }; export type timeUnit = keyof typeof unitMap | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year'; export {};