UNPKG

@qntm-code/utils

Version:

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

40 lines (39 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.msToUnit = void 0; const index_js_1 = require("./index.js"); /** * Converts milliseconds into a TimeUnit */ function msToUnit(value, unit) { switch (unit) { case index_js_1.TimeUnit.Millisecond: case index_js_1.TimeUnit.Milliseconds: { return value; } case index_js_1.TimeUnit.Second: case index_js_1.TimeUnit.Seconds: { return value / 1000; } case index_js_1.TimeUnit.Minute: case index_js_1.TimeUnit.Minutes: { return value / 60000; } case index_js_1.TimeUnit.Hour: case index_js_1.TimeUnit.Hours: { return value / 3600000; } case index_js_1.TimeUnit.Day: case index_js_1.TimeUnit.Days: { return value / 86400000; } case index_js_1.TimeUnit.Week: case index_js_1.TimeUnit.Weeks: { return value / 604800000; } default: { throw new Error(`Unknown TimeUnit: ${unit}`); } } } exports.msToUnit = msToUnit;