UNPKG

@genexus/web-standard-functions

Version:

GeneXus JavaScript standard functions library for web generators

71 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toFormattedString = void 0; const padLeft_1 = require("../text/padLeft"); const toFormattedString_1 = require("../date/toFormattedString"); const toFormattedString = (dateFrom, dateFormat, timeFormat, picture) => { if (!dateFormat) { dateFormat = "MDY"; } if (!timeFormat) { timeFormat = 12; } if (!picture) { picture = "99/99/99 99:99"; } let datePart = ""; let datePartPicture = picture.split(" ")[0]; datePart = (0, toFormattedString_1.toFormattedString)(dateFrom, dateFormat, datePartPicture); let timePartPicture = picture.split(" ")[1]; let timePart = ""; let type = ""; let hours = (0, padLeft_1.padLeft)(String(dateFrom.getHours()), 2, "0"); let minutes = (0, padLeft_1.padLeft)(String(dateFrom.getMinutes()), 2, "0"); let seconds = (0, padLeft_1.padLeft)(String(dateFrom.getSeconds()), 2, "0"); let milliseconds = (0, padLeft_1.padLeft)(String(dateFrom.getMilliseconds()), 3, "0"); // timeFormat: 12 timeFormat: 24 if (timeFormat === 12) { if (Number(hours) < 12) { type = "AM"; } else { type = "PM"; } hours = String(Number(hours) % 12 || 12); if (hours.toString().length === 1) { hours = "0" + hours; } } if (!timePartPicture) { timePart = ""; } else { switch (timePartPicture.split(":").length) { case 1: timePart = hours; break; case 2: timePart = hours + ":" + minutes; break; case 3: timePart = hours + ":" + minutes + ":" + seconds; if (timePartPicture.split(".").length === 2) { timePart = timePart + "." + milliseconds; } break; } } if (timePart === "") { return datePart; } else { if (type !== "") { return datePart + " " + timePart + " " + type; } else { return datePart + " " + timePart; } } }; exports.toFormattedString = toFormattedString; //# sourceMappingURL=toFormattedString.js.map