UNPKG

@qntm-code/utils

Version:

A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.

36 lines (35 loc) 881 B
import { TimeUnit } from './index.js'; /** * Converts milliseconds into a TimeUnit */ export function msToUnit(value, unit) { switch (unit) { case TimeUnit.Millisecond: case TimeUnit.Milliseconds: { return value; } case TimeUnit.Second: case TimeUnit.Seconds: { return value / 1000; } case TimeUnit.Minute: case TimeUnit.Minutes: { return value / 60000; } case TimeUnit.Hour: case TimeUnit.Hours: { return value / 3600000; } case TimeUnit.Day: case TimeUnit.Days: { return value / 86400000; } case TimeUnit.Week: case TimeUnit.Weeks: { return value / 604800000; } default: { throw new Error(`Unknown TimeUnit: ${unit}`); } } }