import { Duration, Locale, addDays, eachMonthOfInterval, eachQuarterOfInterval, isAfter, isThisYear, isToday, isYesterday, startOfWeek, subDays, subMonths, subQuarters, subWeeks } from "date-fns"; import { formatTimeDuration, formatLongDateTimeStampWithLocale } from "../internal-flex-commons/src"; import { fromZonedTime, toZonedTime } from "date-fns-tz"; type TimeDuration = Duration; type DurationMapping = { years?: string; months?: string; days?: string; hours?: string; minutes?: string; seconds?: string; }; interface DurationDisplayOptions { format?: DurationMapping; zero?: boolean; delimiter?: string; } /** * Return a string representing the day according to the below rules. * If today, returns 'Today'. * If yesterday, returns 'Yesterday'. * If within the last year, return in format: Mon, Feb 7th. * If before the last year, return in format: Feb 7th, 2022. * If includeTime is true, the string returned include the time. * An invalid date object input will result in an empty string return. * @param {Date} date - The date we are looking at. * @param {boolean} includeTime - If true, it includes the time. * @param {boolean} toLowercase - Optional parameter that defaults to false. If true, sets date Text (ie Mon, Feb 7th) to all lowercase. * @returns {string} The date string to be shown in the time separator. * @example * getDatetimeDisplay(new Date("Invalid Date"), false, false) // "" * getDatetimeDisplay(new Date("2021-01-01")) // Jan 1st, 2021 * getDatetimeDisplay(new Date("2021-01-01"), true) // Jan 1st, 2021 at 12:00am * getDatetimeDisplay(new Date("2021-01-01"), true, true) // jan 1st, 2021 at 12:00am * getDatetimeDisplay(new Date("2021-09-21"), true, false) // Today at 12:00am (Assuming today is Sep 21st, 2021) * getDatetimeDisplay(new Date("2021-09-20"), true, false) // Yesterday at 12:00am (Assuming today is Sep 21st, 2021) */ declare const getDatetimeDisplay: (date: Date, includeTime?: boolean, toLowercase?: boolean) => string; /** * This method formats dates based a duration value. The format value is optional and defaults to 'normal'. * * format type 'short' formats date as following: * 0sec - 59min - MM:SS * 1h - 23h59min - HHh MMmin * from 1d - DDd HHh * format type: 'full' return string representation of time in (dd):(hh):mm:ss format * format type: 'compact' returns string representation of time in seconds, minutes or hours * format type: 'normal' Create a string representing a time given days, hours, minutes, and seconds. * Only display the necessary information (eg. If hours = 0, do not even display hours). * Stays the same for all locales (by design). * @param {TimeDuration} duration - The amount of time in years, months, days, minutes, seconds. * @param {string} format - converts the time duration to a custom defined format. * @returns {string} The time in DHMS format. * @example * formatTimeDurationByDuration({ hours: 1, minutes: 1, seconds: 1 }) // 01:01:01 * formatTimeDurationByDuration({ hours: 1, minutes: 1, seconds: 1 }, "compact") // 1h * formatTimeDurationByDuration({ hours: 1, minutes: 1, seconds: 1 }, "normal") // 1h 1m 1s * formatTimeDurationByDuration({ hours: 1, minutes: 1, seconds: 1 }, "short") // 1h 1min */ declare const formatTimeDurationByDuration: (duration: TimeDuration, format?: "full" | "compact" | "short" | "normal") => string; declare const formatSeparatorDate: (date: Date) => string; /** * Formats a timestamp to a Long localized time format. * @param {string} timeStamp - The timestamp to format. * @param {Locale} locale - The locale to use for formatting. * @returns {string} The formatted timestamp. * @example * formatTimeStamp("2021-01-01T12:00:00") // 12:00 PM */ declare const formatTimeStamp: (timeStamp: string, locale?: Locale) => string; /** * Returns the amount of time in years-months-days-hours-minutes-seconds * between two given dates (by default compares to today's date). * @param {Date} startDate - The start date to compare with. * @param {Date} endDate - The end date to compare with, by default "today". * @returns {TimeDuration} - The amount of time in years, months, days, minutes, seconds. * @example * getTimePassed(new Date("2021-01-01"), new Date("2021-01-02")) // { years: 0, months: 0, days: 1, hours: 0, minutes: 0, seconds: 0 } * getTimePassed(new Date("2021-01-01")) // { years: 0, months: 0, days: 1, hours: 0, minutes: 0, seconds: 0 } (compares to today's date) */ declare const getTimePassed: (startDate: Date, endDate?: undefined | Date) => TimeDuration; /** * Method to display milliseconds in a format of minutes and seconds (unless * differently specified). * Same as getDurationDisplayByDate but gets milliseconds as an input, instead of a date. * Does not localise this format. * @param {number} milliseconds - The amount of milliseconds to get a duration display for. * @param {DurationDisplayOptions} options - Options for formatting the duration display. * @returns {string} The duration calculated. * @example * getDurationDisplayByMilliseconds(1000) // 1s * getDurationDisplayByMilliseconds(10000, { format: { minutes: "m", seconds: "s" } }) // 0m 10s */ declare const getDurationDisplayByMilliseconds: (milliseconds: number, options?: DurationDisplayOptions) => string; /** * Method to calculate the amount of time between a date provided and now, * displayed in years, months, days, hours, minutes, seconds (unless differently specified). * Same as getDurationDisplay but gets a Date as an input, instead of separate units. * Does not localise this format. * @param {Date} date - The start date for which the duration needs to be calculated (comparing with now). * @param {DurationDisplayOptions} options - Options for formatting the duration display. * @returns {string} The duration calculated. * @example * getDurationDisplayByDate(new Date("2021-01-01")) // 1y 1mo 1d 1h 1m 1s * getDurationDisplayByDate(new Date("2021-01-01"), { format: { years: "y", months: "mo", days: "d", hours: "hr", minutes: "m", seconds: "s" } }) // 1y 1mo 1d 1hr 1m 1s */ declare const getDurationDisplayByDate: (date: Date, options?: DurationDisplayOptions) => string; /** * Get timestamp in am/pm 12h format, except for locales where a 24h format is used. * @param {string} dateTime - Datetime string as 2022-05-19T12:00:00. * @returns {string} Formatted timestamp in en-US as 12:00am. * @example * getFormattedAMPM("2022-05-19T12:00:00") // 12:00pm * getFormattedAMPM("2022-05-19T00:00:00") // 12:00am */ declare const getFormattedAMPM: (dateTime: string) => string; declare const isWithinOneSecond: (milliseconds: number) => boolean; declare const isSameDate: (date1: Date, date2: Date) => boolean; /** * Get today's date in yyyy/mm/dd format * @returns {string} date in yyyy/mm/dd format. * @example * getTodayDate() // 2019-12-30 */ declare const getTodayDate: () => string; /** * Get a date n months back from now in yyyy/mm/dd format * @returns {string} date in yyyy/mm/dd format. * @example * getDateMonthsBackFromNow(1) // 2019-12-30 * @example * getDatetimeDisplay(new Date("Invalid Date"), false, false) // "" */ /** * Get a date n months back from now in yyyy/mm/dd format. * @param {number} months - The number of months to go back. * @returns {string} The date in yyyy/mm/dd format. * @example * getDateMonthsBackFromNow(1) // 2019-12-30 */ declare const getDateMonthsBackFromNow: (months: number) => string; /** * Validate if the date object is valid and if so, apply the format + options. * An invalid date object input will result in an empty string return. * @param {Date} date - The date object to validate and format. * @param {string} format - The format to apply to the date. * @param {any} options - Additional options for formatting. * @returns {string} The formatted date. * @example * validateAndFormatDate(new Date("2021-01-01"), "MMM do, yyyy", {}); // Jan 1st, 2021 * validateAndFormatDate(new Date("Invalid Date"), "MMM do, yyyy", {}); // "" */ declare const validateAndFormatDate: (date: Date, format: string, options?: any) => string; /** * Convert timestamp into date in dd/mm/yyyy format * @param {string} timeStamp - The timestamp to convert. * @returns {string} The formatted date. * @example * getUTCDate("2023-12-06T18:53:19Z"); // "6/12/2023" * getUTCDate("2023-12-01T01:54:53Z"); // "1/12/2023" * @deprecated * @deprecatedSince 2.9.0 * @altRecommendation validateAndFormatDate * @altRecommendationExample validateAndFormatDate(new Date("2021-01-01"), "M/d/yyyy"); // 1/1/2021 */ declare const getDateString: (timeStamp: string) => string; /** * Check if the date object is valid. * @param {Date} date - The date object to check. * @returns {boolean} True if the date object is valid, false otherwise. * @example * isValidDateObject(new Date("2021-01-01")) // true * isValidDateObject(new Date("Invalid Date")) // false * isValidDateObject(new Date("new Date("2024-13-01")")) // false * @since 2.9.0 */ declare const isValidDateObject: (date: Date) => boolean; /** * Checks if the date is a valid and complete ISO date string. * @param {string} dateStr - The date string to check. * @returns {boolean} True if the date string is a valid ISO date string, false otherwise. * @example * isValidIsoDateString("2021-01-01T12:00:00") // true * isValidIsoDateString("2021-01-01T12:00:00Z") // true * isValidIsoDateString("2021-01-01T12:00:00+00:00") // true * isValidIsoDateString("2021-01-01") // false * isValidIsoDateString("12:00:00") // false * isValidIsoDateString("Invalid Date") // false * isValidIsoDateString("new Date("2024-13-01")") // false * @since 2.9.0 */ declare const isValidIsoDateString: (dateStr: string) => boolean; /** * Determines how much time has passed since the given date. * @param {Date} date - The date to compare to now. * @param {Locale} locale - The locale to use for formatting. * @returns {string} A string representing the time passed. * @example (Assumes today is May 21, 2024 at 18:50pm PST) * getDistanceToNow(new Date("2024-05-21T18:51:00")) // 2 minutes ago (occurs in the past) * getDistanceToNow(new Date("2024-05-21T17:25:00")) // about 1 hour ago (occurs in the past) * getDistanceToNow(new Date("2024-05-21T17:25:00")) // about 1 hour ago (occurs in the past) * getDistanceToNow(new Date("2024-05-21T18:25:00")) // 30 minutes ago (occurs in the past) * getDistanceToNow(new Date("2024-05-21T18:13:45")) // 42 minutes ago (occurs in the past) * getDistanceToNow(new Date("2024-05-21T19:25:00")) // in 32 minutes (occurs in the future) */ declare const getDistanceToNow: (date: Date, locale?: Locale) => string; export { TimeDuration, addDays, eachMonthOfInterval, eachQuarterOfInterval, formatLongDateTimeStampWithLocale, formatSeparatorDate, formatTimeDuration, formatTimeDurationByDuration, formatTimeStamp, fromZonedTime, getDateMonthsBackFromNow, getDateString, getDatetimeDisplay, getDistanceToNow, getDurationDisplayByDate, getDurationDisplayByMilliseconds, getFormattedAMPM, getTimePassed, getTodayDate, isAfter, isSameDate, isThisYear, isToday, isValidDateObject, isValidIsoDateString, isWithinOneSecond, isYesterday, startOfWeek, subDays, subMonths, subQuarters, subWeeks, toZonedTime, validateAndFormatDate };