UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

38 lines 2.1 kB
/** * Calculates the time duration between the current time and a given time offset. * * @param {Date} timeData - The target time as a Date object. * @param {string} [durationType='asSeconds'] - The type of duration to return. Can be 'asMilliseconds', 'asSeconds', 'asMinutes', 'asHours', 'asDays'. * @param {Date|null} [now=null] - The current time as a Date object. Defaults to the current date and time if not provided. * @returns {number|null} The calculated duration in the specified unit, or `null` if `timeData` is not provided. */ export function getTimeDuration(timeData?: Date, durationType?: string, now?: Date | null): number | null; /** * Formats a custom timer string based on total seconds and a detail level. * Includes proper reallocation of lower units into higher ones, ensuring consistent hierarchy. * * @param {number} totalSeconds - The total amount of seconds to convert. * @param {'seconds'|'minutes'|'hours'|'days'|'months'|'years'} [level] - The highest level to calculate and display. * @param {string} [format='{time}'] - Output template with placeholders like {years}, {months}, {days}, {hours}, {minutes}, {seconds}, {time}, {total}. * @returns {string} The formatted timer string. */ export function formatCustomTimer(totalSeconds: number, level?: "seconds" | "minutes" | "hours" | "days" | "months" | "years", format?: string): string; /** * Formats a duration (in seconds) into a timer string showing only hours, minutes, and seconds. * * Example output: "05:32:10" * * @param {number} seconds - The total number of seconds to format. * @returns {string} The formatted timer string in "HH:MM:SS" format. */ export function formatTimer(seconds: number): string; /** * Formats a duration (in seconds) into a timer string including days, hours, minutes, and seconds. * * Example output: "2d 05:32:10" * * @param {number} seconds - The total number of seconds to format. * @returns {string} The formatted timer string in "Xd HH:MM:SS" format. */ export function formatDayTimer(seconds: number): string; //# sourceMappingURL=clock.d.mts.map