/** * Utility functions for formatting a timestamp (i.e. a single instant in time). * * Expected inputs are: * - the timestamp itself as an epoch milliseconds value * - the named format type to use (see `SupportedTimeFormat` below) * - locale info, which includes: * - the time zone to use for display * * The `formatTimestamp` function can be used to just get a formatted string. * * The `formatTimestampAsParts` function returns a richer list of objects that separate * the date/time/timeZone portion of the formatted output and include screen-reader-friendly labels. * * This approach uses a polyfill for the upcoming [Temporal API](https://tc39.es/proposal-temporal/docs/index.html) and * the relatively new [Intl.DateTimeFormat API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) * as a way to work directly with the browser to handle/format dates, instead of delegating that to a library. * */ import { Temporal } from 'temporal-polyfill'; export type SupportedTimeFormat = 'date' | 'dateCompact' | 'dateVerbose' | 'time' | 'timeCompact' | 'timePrecise' | 'timeExtraPrecise' | 'dateTime' | 'dateTimeNoTimezone' | 'dateCompactTime' | 'dateTimeCompact' | 'dateCompactTimeCompact' | 'dateTimePrecise' | 'dateTimePreciseNoTimezone' | 'dateTimeExtraPrecise' | 'dateVerboseTime' | 'dateVerboseTimePrecise' | 'dateVerboseTimeExtraPrecise' | 'isoDate' | 'isoTime' | 'isoLocal' | 'isoWithOffset'; type FormatPartOutput = { name: 'time' | 'date' | 'timeZone' | 'dateTime'; value: string; label: string; }; type formatRangeOutput = { from: FormatPartOutput[]; to: FormatPartOutput[]; fromString: string; toString: string; }; export type LocaleInfo = { tz?: string; ianaTimezone?: string; serializedTimezone?: string; utcOffset?: number; /** * Denotes whether to display time with 12 hour time format. Preference can be used by passing in * "sf_12hourTimeFormat" from current user service. When not passed, 24 hour time is used by default. */ twelveHourTimeFormat?: boolean; }; export declare const formatTimestamp: (ts: number, formatName: SupportedTimeFormat, localeInfo: LocaleInfo) => string; export declare const formatTimestampAsParts: (ts: number, formatName: SupportedTimeFormat, localeInfo: LocaleInfo) => FormatPartOutput[]; export declare const tsToZdt: (ts: number, localeInfo: LocaleInfo) => Temporal.ZonedDateTime; export declare const currentTimeInTimezone: (locale: LocaleInfo) => Temporal.ZonedDateTime; export declare const formatTimestampRange: (fromTs: number, toTs: number, locale: LocaleInfo, formatName: SupportedTimeFormat) => formatRangeOutput; export {};