UNPKG

matrix-react-sdk

Version:
120 lines (119 loc) 6.74 kB
import { Optional } from "matrix-events-sdk"; export declare const MINUTE_MS = 60000; export declare const HOUR_MS: number; export declare const DAY_MS: number; /** * Returns array of 7 weekday names, from Sunday to Saturday, internationalised to the user's language. * @param weekday - format desired "short" | "long" | "narrow" */ export declare function getDaysArray(weekday?: Intl.DateTimeFormatOptions["weekday"]): string[]; /** * Returns array of 12 month names, from January to December, internationalised to the user's language. * @param month - format desired "numeric" | "2-digit" | "long" | "short" | "narrow" */ export declare function getMonthsArray(month?: Intl.DateTimeFormatOptions["month"]): string[]; /** * Formats a given date to a date & time string. * * The output format depends on how far away the given date is from now. * Will use the browser's default time zone. * If the date is today it will return a time string excluding seconds. See {@formatTime}. * If the date is within the last 6 days it will return the name of the weekday along with the time string excluding seconds. * If the date is within the same year then it will return the weekday, month and day of the month along with the time string excluding seconds. * Otherwise, it will return a string representing the full date & time in a human friendly manner. See {@formatFullDate}. * @param date - date object to format * @param showTwelveHour - whether to use 12-hour rather than 24-hour time. Defaults to `false` (24 hour mode). * Overrides the default from the locale, whether `true` or `false`. * @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale */ export declare function formatDate(date: Date, showTwelveHour?: boolean, locale?: string): string; /** * Formats a given date to a human-friendly string with short weekday. * Will use the browser's default time zone. * @example "Thu, 17 Nov 2022" in en-GB locale * @param date - date object to format * @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale */ export declare function formatFullDateNoTime(date: Date, locale?: string): string; /** * Formats a given date to a date & time string, optionally including seconds. * Will use the browser's default time zone. * @example "Thu, 17 Nov 2022, 4:58:32 pm" in en-GB locale with showTwelveHour=true and showSeconds=true * @param date - date object to format * @param showTwelveHour - whether to use 12-hour rather than 24-hour time. Defaults to `false` (24 hour mode). * Overrides the default from the locale, whether `true` or `false`. * @param showSeconds - whether to include seconds in the time portion of the string * @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale */ export declare function formatFullDate(date: Date, showTwelveHour?: boolean, showSeconds?: boolean, locale?: string): string; /** * Formats dates to be compatible with attributes of a `<input type="date">`. Dates * should be formatted like "2020-06-23" (formatted according to ISO8601). * * @param date The date to format. * @returns The date string in ISO8601 format ready to be used with an `<input>` */ export declare function formatDateForInput(date: Date): string; /** * Formats a given date to a time string including seconds. * Will use the browser's default time zone. * @example "4:58:32 PM" in en-GB locale with showTwelveHour=true * @example "16:58:32" in en-GB locale with showTwelveHour=false * @param date - date object to format * @param showTwelveHour - whether to use 12-hour rather than 24-hour time. Defaults to `false` (24 hour mode). * Overrides the default from the locale, whether `true` or `false`. * @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale */ export declare function formatFullTime(date: Date, showTwelveHour?: boolean, locale?: string): string; /** * Formats a given date to a time string excluding seconds. * Will use the browser's default time zone. * @example "4:58 PM" in en-GB locale with showTwelveHour=true * @example "16:58" in en-GB locale with showTwelveHour=false * @param date - date object to format * @param showTwelveHour - whether to use 12-hour rather than 24-hour time. Defaults to `false` (24 hour mode). * Overrides the default from the locale, whether `true` or `false`. * @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale */ export declare function formatTime(date: Date, showTwelveHour?: boolean, locale?: string): string; export declare function formatSeconds(inSeconds: number): string; export declare function formatTimeLeft(inSeconds: number): string; export declare function wantsDateSeparator(prevEventDate: Optional<Date>, nextEventDate: Optional<Date>): boolean; export declare function formatFullDateNoDay(date: Date): string; /** * Returns an ISO date string without textual description of the date (ie: no "Wednesday" or similar) * @param date The date to format. * @returns The date string in ISO format. */ export declare function formatFullDateNoDayISO(date: Date): string; /** * Formats a given date to a string. * Will use the browser's default time zone. * @example 17/11/2022 in en-GB locale * @param date - date object to format * @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale */ export declare function formatFullDateNoDayNoTime(date: Date, locale?: string): string; export declare function formatRelativeTime(date: Date, showTwelveHour?: boolean): string; /** * Formats duration in ms to human-readable string * Returns value in the biggest possible unit (day, hour, min, second) * Rounds values up until unit threshold * i.e. 23:13:57 -> 23h, 24:13:57 -> 1d, 44:56:56 -> 2d */ export declare function formatDuration(durationMs: number): string; /** * Formats duration in ms to human-readable string * Returns precise value down to the nearest second * i.e. 23:13:57 -> 23h 13m 57s, 44:56:56 -> 1d 20h 56m 56s */ export declare function formatPreciseDuration(durationMs: number): string; /** * Formats a timestamp to a short date * Similar to {@formatFullDateNoDayNoTime} but with 2-digit on day, month, year. * @example 25/12/22 in en-GB locale * @param timestamp - epoch timestamp * @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale * @returns {string} formattedDate */ export declare const formatLocalDateShort: (timestamp: number, locale?: string) => string;