UNPKG

@reservoir0x/relay-kit-ui

Version:

Relay is the Fastest and Cheapest Way to Bridge and Transact Across Chains.

36 lines 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.get15MinuteInterval = exports.formatSeconds = exports.relativeTime = void 0; const tslib_1 = require("tslib"); const dayjs_1 = tslib_1.__importDefault(require("dayjs")); const relativeTime_js_1 = tslib_1.__importDefault(require("dayjs/plugin/relativeTime.js")); dayjs_1.default.extend(relativeTime_js_1.default); const relativeTime = (timeString, from, withoutSuffix) => { return from ? `${(0, dayjs_1.default)(timeString).from(from, withoutSuffix)}` : `${(0, dayjs_1.default)(timeString).fromNow(withoutSuffix)}`; }; exports.relativeTime = relativeTime; const formatSeconds = (seconds) => { seconds = Number(seconds); const d = Math.floor(seconds / (3600 * 24)); const h = Math.floor((seconds % (3600 * 24)) / 3600); const m = Math.floor((seconds % 3600) / 60); const s = Math.floor(seconds % 60); const dDisplay = d > 0 ? d + (d == 1 ? ' d' : 'd ') : ''; const hDisplay = h > 0 ? h + (h == 1 ? ' h' : 'h ') : ''; const mDisplay = m > 0 ? m + (m == 1 ? ' m' : 'm ') : ''; const sDisplay = s > 0 ? s + (s == 1 ? ' s' : 's ') : ''; return `${dDisplay} ${hDisplay} ${mDisplay} ${sDisplay}`.trim(); }; exports.formatSeconds = formatSeconds; const get15MinuteInterval = () => { const now = new Date(); const minutes = now.getUTCMinutes(); const interval = Math.floor(minutes / 15); const intervalStart = new Date(now); intervalStart.setUTCMinutes(interval * 15, 0, 0); return intervalStart.getTime(); }; exports.get15MinuteInterval = get15MinuteInterval; //# sourceMappingURL=time.js.map