"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var zeroPadding_1 = __importDefault(require("../number/zeroPadding"));
var isStr_1 = __importDefault(require("../string/isStr"));
var YEAR_DIGITS = 4;
var SECOND_DIGITS = 3;
/**
* Generate an ID with format YYYYMMDDHHmmssSSS
* @category dateTime
* @module generateDateTimeID
*/
var generateDateTimeID = function () {
var date = new Date();
var YYYY = (0, zeroPadding_1.default)(date.getFullYear(), YEAR_DIGITS);
var MM = date.getMonth();
var DD = date.getUTCDate();
var hh = date.getUTCHours();
var mm = date.getUTCMinutes();
var ss = date.getUTCSeconds();
var SSS = (0, zeroPadding_1.default)(date.getUTCMilliseconds(), SECOND_DIGITS);
return [YYYY, MM, DD, hh, mm, ss, SSS]
// Add zero padding for all 2-digit segments
// Do not pad if it is already of type string, which means it is padded.
.map(function (n) { return (0, isStr_1.default)(n) ? n : (0, zeroPadding_1.default)(n); })
.join('');
};
exports.default = generateDateTimeID;
Source