UNPKG

orgdo

Version:

Command-line tool to manage the Todo lists

58 lines (57 loc) 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function paddingLeft(str, size) { return (str + " ".repeat(size)).slice(0, size); } exports.paddingLeft = paddingLeft; function prependZero(str, size) { return ("0".repeat(size) + str).slice(-1 * size); } exports.prependZero = prependZero; function paddingRight(str, size) { return (" ".repeat(size) + str).slice(-1 * size); } exports.paddingRight = paddingRight; function dateFormat(date) { const year = "" + date.getFullYear(); const month = prependZero("" + (date.getMonth() + 1), 2); const day = prependZero("" + date.getDate(), 2); const hour = prependZero("" + date.getHours(), 2); const minute = prependZero("" + date.getMinutes(), 2); const ymd = `${year}-${month}-${day}`; if (hour === "00" && minute === "00") { return ymd; } return ymd + ` ${hour}:${minute}`; } exports.dateFormat = dateFormat; function shortTimeStr(timestr) { const date = new Date(timestr); const now = new Date(); if (date.getFullYear() === now.getFullYear()) { timestr = timestr.slice(5); } else { return timestr.slice(2); } if (date.getMonth() === now.getMonth() && date.getDate() === now.getDate()) { return timestr.slice(6); } return timestr; } exports.shortTimeStr = shortTimeStr; function clearTimeInfo(date) { const ret = new Date(date.toString()); ret.setHours(0); ret.setMinutes(0); ret.setSeconds(0); ret.setMilliseconds(0); return ret; } exports.clearTimeInfo = clearTimeInfo; function strToArr(obj, key) { if (obj[key] && typeof obj[key] === "string") { obj[key] = [obj[key]]; } } exports.strToArr = strToArr;