From 6d87b3e10db11a8755b4049ba82732c6ec4f776c Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Tue, 16 Jul 2019 11:20:20 +0200 Subject: [PATCH] [FIX] versionInfo: Use correct buildTimestamp format --- lib/processors/versionInfoGenerator.js | 16 +++++++++++++++- test/lib/tasks/generateVersionInfo.js | 8 ++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/processors/versionInfoGenerator.js b/lib/processors/versionInfoGenerator.js index 17807463a..61b4ab31f 100644 --- a/lib/processors/versionInfoGenerator.js +++ b/lib/processors/versionInfoGenerator.js @@ -1,5 +1,19 @@ const resourceFactory = require("@ui5/fs").resourceFactory; +function pad(v) { + return String(v).padStart(2, "0"); +} +function getTimestamp() { + const date = new Date(); + const year = date.getFullYear(); + const month = pad(date.getMonth() + 1); + const day = pad(date.getDate()); + const hours = pad(date.getHours()); + const minutes = pad(date.getMinutes()); + // yyyyMMddHHmm + return year + month + day + hours + minutes; +} + /** * Creates sap-ui-version.json. * @@ -18,7 +32,7 @@ module.exports = async function({options}) { throw new Error("[versionInfoGenerator]: Missing options parameters"); } - const buildTimestamp = new Date().getTime(); + const buildTimestamp = getTimestamp(); const versionJson = { name: options.rootProjectName, version: options.rootProjectVersion, // TODO: insert current application version here diff --git a/test/lib/tasks/generateVersionInfo.js b/test/lib/tasks/generateVersionInfo.js index bdb106122..59d67335e 100644 --- a/test/lib/tasks/generateVersionInfo.js +++ b/test/lib/tasks/generateVersionInfo.js @@ -72,9 +72,13 @@ async function assertCreatedVersionInfo(t, oExpectedVersionInfo, options) { const buffer = await resource.getBuffer(); const currentVersionInfo = JSON.parse(buffer); - delete currentVersionInfo.buildTimestamp; + + t.is(currentVersionInfo.buildTimestamp.length, 12, "Timestamp should have length of 12 (yyyyMMddHHmm)"); + + delete currentVersionInfo.buildTimestamp; // removing to allow deep comparison currentVersionInfo.libraries.forEach((lib) => { - delete lib.buildTimestamp; + t.is(lib.buildTimestamp.length, 12, "Timestamp should have length of 12 (yyyyMMddHHmm)"); + delete lib.buildTimestamp; // removing to allow deep comparison }); t.deepEqual(currentVersionInfo, oExpectedVersionInfo, "Correct content"); }