UNPKG

date-and-time

Version:

The simplest, most intuitive date and time library

115 lines (107 loc) 3.35 kB
/** @preserve Copyright (c) KNOWLEDGECODE - MIT License */ type CompiledObject = string[]; interface DateLike { /** * Returns the year of the date. */ getFullYear(): number; /** * Returns the month of the date (0-11). */ getMonth(): number; /** * Returns the day of the month (1-31). */ getDate(): number; /** * Returns the hours of the date (0-23). */ getHours(): number; /** * Returns the minutes of the date (0-59). */ getMinutes(): number; /** * Returns the seconds of the date (0-59). */ getSeconds(): number; /** * Returns the milliseconds of the date (0-999). */ getMilliseconds(): number; /** * Returns the day of the week (0-6, where 0 is Sunday). */ getDay(): number; /** * Returns the time value in milliseconds since the Unix epoch (January 1, 1970). */ getTime(): number; /** * Returns the timezone offset in minutes from UTC. */ getTimezoneOffset(): number; } interface LocaleOptions { compiledObj: CompiledObject; style: 'long' | 'short' | 'narrow'; case?: 'uppercase' | 'lowercase'; } interface Locale { getLocale: () => string; getMonthList: (options: LocaleOptions) => string[]; getDayOfWeekList: (options: LocaleOptions) => string[]; getMeridiemList: (options: LocaleOptions) => string[]; } interface Numeral { encode: (str: string) => string; decode: (str: string) => string; } interface TimeZone { zone_name: string; gmt_offset: number[]; } interface FormatterPluginOptions { /** * The hour format to use for formatting. * This is used when the hour is in 12-hour format. * It can be 'h11' for 11-hour format or 'h12' for 12-hour format. */ hour12: 'h11' | 'h12'; /** * The hour format to use for formatting. * This is used when the hour is in 24-hour format. * It can be 'h23' for 23-hour format or 'h24' for 24-hour format. */ hour24: 'h23' | 'h24'; /** * The numeral system to use for formatting numbers. * This is an object that provides methods to encode and decode numbers in the specified numeral system. */ numeral: Numeral; /** * The calendar system to use for formatting dates. * This can be 'buddhist' for Buddhist calendar or 'gregory' for Gregorian calendar. */ calendar: 'buddhist' | 'gregory'; /** * The time zone to use for formatting dates and times. * This can be a specific time zone object or 'UTC' to use Coordinated Universal Time. * If not specified, it defaults to undefined, which means the local time zone will be used. */ timeZone: TimeZone | 'UTC' | undefined; /** * The locale to use for formatting dates and times. * This is an object that provides methods to get localized month names, day names, and meridiems. */ locale: Locale; } declare abstract class FormatterPlugin { [key: string]: (d: DateLike, options: FormatterPluginOptions, compiledObj: CompiledObject) => string; } declare class Formatter extends FormatterPlugin { z(d: DateLike, options: FormatterPluginOptions): string; zz(d: DateLike, options: FormatterPluginOptions): string; } declare const formatter: Formatter; export { formatter };