UNPKG

time-converter-ts

Version:
112 lines (111 loc) 4.3 kB
/** * Represents a set of time units and their corresponding values. * * @property ms - Milliseconds. * @property s - Seconds. * @property m - Minutes. * @property h - Hours. * @property d - Days. * @property w - Weeks. * @property y - Years. */ export interface TimeData { ms: number; s: number; m: number; h: number; d: number; w: number; y: number; } /** * Converts milliseconds to a TimeData object. * @param milliseconds - The number of milliseconds to convert. * @param decimals - The number of decimal places to round to (default is 2). * @returns TimeData object with the equivalent time in milliseconds (ms), seconds (s), minutes (m), hours (h), days (d), weeks (w), and years (y). * @example * ```ts * const timeData = ms(1500); * console.log(timeData); * // Output: { ms: 1500, s: 1.5, m: 0.03, h: 0, d: 0, w: 0, y: 0 } * ``` */ export declare function ms(milliseconds: number, decimals?: number): TimeData; /** * Converts seconds to a TimeData object. * @param seconds - The number of seconds to convert. * @param decimals - The number of decimal places to round to (default is 2). * @returns TimeData object with the equivalent time in milliseconds (ms), seconds (s), minutes (m), hours (h), days (d), weeks (w), and years (y). * @example * ```ts * const timeData = s(180); * console.log(timeData); * // Output: { ms: 180000, s: 180, m: 3, h: 0.05, d: 0, w: 0, y: 0 } * ``` */ export declare function s(seconds: number, decimals?: number): TimeData; /** * Converts minutes to a TimeData object. * @param minutes - The number of minutes to convert. * @param decimals - The number of decimal places to round to (default is 2). * @returns TimeData object with the equivalent time in milliseconds (ms), seconds (s), minutes (m), hours (h), days (d), weeks (w), and years (y). * @example * ```ts * const timeData = m(3); * console.log(timeData); * // Output: { ms: 180000, s: 180, m: 3, h: 0.05, d: 0, w: 0, y: 0 } * ``` */ export declare function m(minutes: number, decimals?: number): TimeData; /** * Converts hours to a TimeData object. * @param hours - The number of hours to convert. * @param decimals - The number of decimal places to round to (default is 2). * @returns TimeData object with the equivalent time in milliseconds (ms), seconds (s), minutes (m), hours (h), days (d), weeks (w), and years (y). * @example * ```ts * const timeData = h(2); * console.log(timeData); * // Output: { ms: 7200000, s: 7200, m: 120, h: 2, d: 0.08, w: 0.01, y: 0 } * ``` */ export declare function h(hours: number, decimals?: number): TimeData; /** * Converts days to a TimeData object. * @param days - The number of days to convert. * @param decimals - The number of decimal places to round to (default is 2). * @returns TimeData object with the equivalent time in milliseconds (ms), seconds (s), minutes (m), hours (h), days (d), weeks (w), and years (y). * @example * ```ts * const timeData = d(1); * console.log(timeData); * // Output: { ms: 86400000, s: 86400, m: 1440, h: 24, d: 1, w: 0.14, y: 0 } * ``` */ export declare function d(days: number, decimals?: number): TimeData; /** * Converts weeks to a TimeData object. * @param weeks - The number of weeks to convert. * @param decimals - The number of decimal places to round to (default is 2). * @returns TimeData object with the equivalent time in milliseconds (ms), seconds (s), minutes (m), hours (h), days (d), weeks (w), and years (y). * @example * ```ts * const timeData = w(1); * console.log(timeData); * // Output: { ms: 604800000, s: 604800, m: 10080, h: 168, d: 7, w: 1, y: 0.02 } * ``` */ export declare function w(weeks: number, decimals?: number): TimeData; /** * Converts years to a TimeData object. * @param years - The number of years to convert. * @param decimals - The number of decimal places to round to (default is 2). * @returns TimeData object with the equivalent time in milliseconds (ms), seconds (s), minutes (m), hours (h), days (d), weeks (w), and years (y). * @example * ```ts * const timeData = y(1); * console.log(timeData); * // Output: { ms: 31536000000, s: 31536000, m: 525600, h: 8760, d: 365, w: 52.14, y: 1 } * ``` */ export declare function y(years: number, decimals?: number): TimeData;