UNPKG

winbox-ui-next

Version:

We Design Vue 2.0: A Vue.js 3 UI Library

28 lines (27 loc) 816 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports[Symbol.toStringTag] = "Module"; const units = [ ["Y", 1e3 * 60 * 60 * 24 * 365], ["M", 1e3 * 60 * 60 * 24 * 30], ["D", 1e3 * 60 * 60 * 24], ["H", 1e3 * 60 * 60], ["m", 1e3 * 60], ["s", 1e3], ["S", 1] ]; function getDateString(millisecond, format) { let leftMillisecond = millisecond; return units.reduce((current, [name, unit]) => { if (current.indexOf(name) !== -1) { const value = Math.floor(leftMillisecond / unit); leftMillisecond -= value * unit; return current.replace(new RegExp(`${name}+`, "g"), (match) => { const len = match.length; return String(value).padStart(len, "0"); }); } return current; }, format); } exports.getDateString = getDateString;