UNPKG

generator-begcode

Version:

Spring Boot + Angular/React/Vue in one handy generator

52 lines (51 loc) 2 kB
export function formatDateForChangelog(now) { const nowUTC = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()); const year = `${nowUTC.getFullYear()}`; let month = `${nowUTC.getMonth() + 1}`; if (month.length === 1) { month = `0${month}`; } let day = `${nowUTC.getDate()}`; if (day.length === 1) { day = `0${day}`; } let hour = `${nowUTC.getHours()}`; if (hour.length === 1) { hour = `0${hour}`; } let minute = `${nowUTC.getMinutes()}`; if (minute.length === 1) { minute = `0${minute}`; } let second = `${nowUTC.getSeconds()}`; if (second.length === 1) { second = `0${second}`; } return `${year}${month}${day}${hour}${minute}${second}`; } export function parseChangelog(changelogDate) { if (!changelogDate) { throw new Error('changelogDate is required.'); } if (typeof changelogDate !== 'string') { throw new Error(`changelogDate ${changelogDate} must be a string.`); } if (changelogDate.length !== 14) { throw new Error(`changelogDate ${changelogDate} is not a valid changelogDate.`); } const formattedDate = `${changelogDate.substring(0, 4)}-${changelogDate.substring(4, 6)}-${changelogDate.substring(6, 8)}T${changelogDate.substring(8, 10)}:${changelogDate.substring(10, 12)}:${changelogDate.substring(12, 14)}+00:00`; return new Date(Date.parse(formattedDate)); } export const parseCreationTimestamp = (creationTimestampOption) => { let creationTimestamp; if (creationTimestampOption) { creationTimestamp = Date.parse(creationTimestampOption); if (!creationTimestamp) { return undefined; } if (creationTimestamp > new Date().getTime()) { throw new Error(`Creation timestamp should not be in the future: ${creationTimestampOption}.`); } } return creationTimestamp; };