"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var isDateString_1 = __importDefault(require("./isDateString"));
var zeroPadding_1 = __importDefault(require("../number/zeroPadding"));
/**
* As the HTML5 input simply doesn't parse the ISO8061 timestamp with local timezone
* So we have to parse it manually
* @param {String} isoDatetime Example value: "2019-05-02T05:28:18.185Z"
* @returns {String}
* A string of type datetime-local, date-local or time-local (depending on options passed).
* Example value: "2019-05-02T13:28"
* @category dateTime
* @module toDateTimeLocal
*/
var toDateTimeLocal = function (isoDatetime, options) {
if (options === void 0) { options = {}; }
if (!(0, isDateString_1.default)(isoDatetime))
return '';
var d = new Date(isoDatetime);
var YYYY = d.getFullYear();
// Month start from ZERO
var MM = (0, zeroPadding_1.default)(d.getMonth() + 1);
var DD = (0, zeroPadding_1.default)(d.getDate());
var HH = (0, zeroPadding_1.default)(d.getHours());
var mm = (0, zeroPadding_1.default)(d.getMinutes());
var date = "".concat(YYYY, "-").concat(MM, "-").concat(DD);
var time = "".concat(HH, ":").concat(mm);
if ((options || {}).dateOnly)
return date;
if ((options || {}).timeOnly)
return time;
return "".concat(date, "T").concat(time);
};
exports.default = toDateTimeLocal;
Source