UNPKG

qpace

Version:

📊 The Quant SDK for Python and Javascript. Written in Rust.

72 lines (71 loc) • 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get }); } _export(exports, { get daysToMs () { return daysToMs; }, get hoursToMs () { return hoursToMs; }, get minutesToMs () { return minutesToMs; }, get monthsToMs () { return monthsToMs; }, get prettifyTime () { return prettifyTime; }, get secondsToMs () { return secondsToMs; }, get yearsToMs () { return yearsToMs; } }); const prettifyTime = (ms)=>{ if (ms == null) return "?"; const hours = Math.floor(ms / 1000 / 60 / 60); const minutes = Math.floor((ms / 1000 / 60 / 60 - hours) * 60); const seconds = Math.floor(((ms / 1000 / 60 / 60 - hours) * 60 - minutes) * 60); let str = ""; if (hours > 0) { str += `${hours}h `; } if (minutes > 0) { str += `${minutes}m `; } if (seconds > 0) { str += `${seconds}s`; } if (str.length === 0) { str = `${Math.round(ms)}ms`; } return str.trim(); }; const secondsToMs = (seconds)=>{ return seconds * 1000; }; const minutesToMs = (minutes)=>{ return secondsToMs(minutes * 60); }; const hoursToMs = (hours)=>{ return minutesToMs(hours * 60); }; const daysToMs = (days)=>{ return hoursToMs(days * 24); }; const monthsToMs = (months)=>{ return daysToMs(months * 30); }; const yearsToMs = (years)=>{ return monthsToMs(years * 12); };