UNPKG

logitar-js

Version:

Helper functions distributed by Logitar.

25 lines (24 loc) 891 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toDateTimeLocal = void 0; function padStart(value, minLength, paddingChar) { if (value.length >= minLength) { return value; } return padStart(paddingChar + value, minLength, paddingChar); } /** * Converts the specified date to a `datetime-local` string. * @param date The date to convert. * @returns The date converted as a `datetime-local` string. */ function toDateTimeLocal(date) { const d = [ padStart(date.getFullYear().toString(), 4, "0"), padStart((date.getMonth() + 1).toString(), 2, "0"), padStart(date.getDate().toString(), 2, "0"), ].join("-"); const t = [padStart(date.getHours().toString(), 2, "0"), padStart(date.getMinutes().toString(), 2, "0")].join(":"); return [d, t].join("T"); } exports.toDateTimeLocal = toDateTimeLocal;