UNPKG

vrem

Version:

An open-source automatic time-tracker

44 lines (43 loc) 1.9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDescriptionByPath = exports.openUrl = exports.makeDurationString = exports.makeTimeStringWithDate = void 0; const path_1 = __importDefault(require("path")); function makeDateString(date) { return (date.getDate().toString().padStart(2, '0') + '.' + (date.getMonth() + 1).toString().padStart(2, '0') + '.' + date.getFullYear()); } function makeTimeString(date) { return (date.getHours().toString().padStart(2, '0') + ':' + (date.getMinutes()).toString().padStart(2, '0') + ':' + date.getSeconds().toString().padStart(2, '0')); } function makeTimeStringWithDate(date = new Date()) { return `${makeTimeString(date)} (${makeDateString(date)})`; } exports.makeTimeStringWithDate = makeTimeStringWithDate; function makeDurationString(ms) { const hours = Math.floor(ms / (60 * 60 * 1000)); ms -= hours * 60 * 60 * 1000; const minutes = Math.floor(ms / 60 / 1000); ms -= minutes * 60 * 1000; const secs = Math.floor(ms / 1000); return `${hours ? hours + 'h ' : ''}${minutes ? minutes + 'm ' : ''}${secs ? secs + 's' : ''}` || '0s'; } exports.makeDurationString = makeDurationString; function openUrl(url) { const command = (process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open'); require('child_process').exec(command + ' ' + url); } exports.openUrl = openUrl; function getDescriptionByPath(programPath) { if (/^http/.test(programPath)) { return programPath; } const parsed = path_1.default.parse(programPath); return parsed.name + parsed.ext; } exports.getDescriptionByPath = getDescriptionByPath;