UNPKG

@splode/obake

Version:

Check merchants for deals.

39 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toTime = exports.toSlashDate = void 0; /** * toSlashDate returns a date string in slash format from a given date. For example, `"2021/05/15"` * * @param d A Date object * @returns The date string */ function toSlashDate(d) { var monthStr = zeroPadNumber(d.getMonth() + 1); return d.getFullYear() + "/" + monthStr + "/" + d.getDate(); } exports.toSlashDate = toSlashDate; /** * toTime returns a time string in 24hr format from a given date. For example, `"13:51:32"` * * @param d A Date object * @returns The time string */ function toTime(d) { var hrStr = zeroPadNumber(d.getHours()); var minStr = zeroPadNumber(d.getMinutes()); var secStr = zeroPadNumber(d.getSeconds()); return hrStr + ":" + minStr + ":" + secStr; } exports.toTime = toTime; /** * zeroPadNumber pads a number with a leading zero and returns it as a string. For example, `9` would become `"09"`. * * @param n The number to pad * @returns A padded number string */ function zeroPadNumber(n) { if (n < 10) return "0" + n; return String(n); } //# sourceMappingURL=date.js.map