Skip to content

Commit

Permalink
Merge pull request #70 from ddoria921/fix-displaying-invalid-date
Browse files Browse the repository at this point in the history
Convert timestamp to JS Date object
  • Loading branch information
lukemelia committed Feb 9, 2023
2 parents 9e67102 + 2525a9d commit 08c46e0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/legacy-table.js
Expand Up @@ -39,7 +39,7 @@ module.exports = CoreObject.extend({

if(key.name === 'timestamp') {
// ember-cli-deploy-revision-data provides a JS Date object, so fall back to that if not milliseconds
let dt = typeof value === 'number' ? DateTime.fromMillis(value) : DateTime.fromJSDate(value);
let dt = typeof value === 'number' ? DateTime.fromMillis(value) : DateTime.fromJSDate(new Date(value));
value = dt.toFormat("yyyy/MM/dd HH:mm:ss");
}

Expand Down
2 changes: 1 addition & 1 deletion lib/scm-table.js
Expand Up @@ -72,7 +72,7 @@ module.exports = CoreObject.extend({
if (this._isWide()) {
let { timestamp } = data;
// ember-cli-deploy-revision-data provides a JS Date object, so fall back to that if not milliseconds
let dt = typeof timestamp === 'number' ? DateTime.fromMillis(timestamp) : DateTime.fromJSDate(timestamp);
let dt = typeof timestamp === 'number' ? DateTime.fromMillis(timestamp) : DateTime.fromJSDate(new Date(timestamp));
let value = dt.toFormat('yyyy/MM/dd HH:mm:ss');
row.push(value);
}
Expand Down
36 changes: 33 additions & 3 deletions tests/index-test.js
Expand Up @@ -164,8 +164,8 @@ describe('displayRevisions plugin', function() {
},
revisions: [
{ revision: "rev:abcdef", timestamp: 1438232435000, deployer: "My Hamster"},
{ revision: "rev:defghi", timestamp: 1032123125000, deployer: "My Hamster", active: true},
{ revision: "rev:jklmno", timestamp: 1032123128000, deployer: "My Hamster"},
{ revision: "rev:defghi", timestamp: '2002-09-15T20:52:05.000Z', deployer: "My Hamster", active: true},
{ revision: "rev:jklmno", timestamp: new Date(1032123128000), deployer: "My Hamster"},
{ revision: "rev:qrstuv", timestamp: 1032123155000, deployer: "My Hamster"},
{ revision: "rev:xyz123", timestamp: 1032123123000, deployer: "My Hamster"}
]
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('displayRevisions plugin', function() {
assert.equal(messages.length, 0);
});

it('transforms timestamps to human-readable dates (yyyy/MM/dd HH:mm:ss)', function() {
it('transforms millisecond timestamps to human-readable dates (yyyy/MM/dd HH:mm:ss)', function() {
plugin.displayRevisions(context);
let expectedFormat = ('yyyy/MM/dd HH:mm:ss');
let expectedDate = DateTime.fromMillis(1438232435000).toFormat(expectedFormat);
Expand All @@ -213,6 +213,36 @@ describe('displayRevisions plugin', function() {
assert.equal(messages.length, 1);
});

it('transforms ISO string timestamps to human-readable dates (yyyy/MM/dd HH:mm:ss)', function() {
plugin.displayRevisions(context);
let expectedFormat = ('yyyy/MM/dd HH:mm:ss');
let expectedDate = DateTime.fromISO('2002-09-15T20:52:05.000Z').toFormat(expectedFormat);

let messages = mockUi.messages.reduce(function(previous, current) {
if (current.indexOf(expectedDate) !== -1) {
previous.push(current);
}

return previous;
}, []);
assert.equal(messages.length, 1);
});

it('transforms JS Date object timestamps to human-readable dates (yyyy/MM/dd HH:mm:ss)', function() {
plugin.displayRevisions(context);
let expectedFormat = ('yyyy/MM/dd HH:mm:ss');
let expectedDate = DateTime.fromJSDate(new Date(1032123128000)).toFormat(expectedFormat);

let messages = mockUi.messages.reduce(function(previous, current) {
if (current.indexOf(expectedDate) !== -1) {
previous.push(current);
}

return previous;
}, []);
assert.equal(messages.length, 1);
});

it('highlights the active revision', function() {
plugin.displayRevisions(context);
let messages = mockUi.messages.reduce(function(previous, current) {
Expand Down

0 comments on commit 08c46e0

Please sign in to comment.