time-conversion-ts
Version:
A tiny typescript library to convert between various time units
39 lines (38 loc) • 1.43 kB
TypeScript
import { ITimeQuantity, TimeUnit } from './types';
export declare class Time {
/**
* Convert a time value from any supported unit to milliseconds
* @param value The time value to convert
* @param units The time value unit type
*/
static toMilliseconds(value: number, units?: TimeUnit): number;
/**
* Convert a time value from milliseconds to any supported unit
* @param ms The millisecond time value to convert
* @param units The time value unit type
*/
static fromMilliseconds(ms: number, units: TimeUnit): number;
/**
* Convert a time value from any supported unit to seconds
* @param value The time value to convert
* @param units The time value unit type
*/
static toSeconds(value: number, units?: TimeUnit): number;
/**
* Convert a time value from seconds to any supported unit
* @param s The second time value to convert
* @param units The time value unit type
*/
static fromSeconds(s: number, units: TimeUnit): number;
/**
* Convert a time quantity to any supported unit
* @param quantity The time quantity
* @param unit The unit type of the time quantity
*/
static from(quantity: ITimeQuantity, unit: TimeUnit): number;
/**
* Assert the passed time unit is valid
* @param unit The unit type to check
*/
static assertValid(unit: TimeUnit): true | never;
}