Skip to content

Commit

Permalink
[FIX] versionInfo: Use correct buildTimestamp format
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Jul 18, 2019
1 parent df7c789 commit 6d87b3e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 15 additions & 1 deletion lib/processors/versionInfoGenerator.js
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions test/lib/tasks/generateVersionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 6d87b3e

Please sign in to comment.