Skip to content

Commit 08c46e0

Browse files
authored
Merge pull request #70 from ddoria921/fix-displaying-invalid-date
Convert timestamp to JS Date object
2 parents 9e67102 + 2525a9d commit 08c46e0

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

lib/legacy-table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = CoreObject.extend({
3939

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

lib/scm-table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = CoreObject.extend({
7272
if (this._isWide()) {
7373
let { timestamp } = data;
7474
// ember-cli-deploy-revision-data provides a JS Date object, so fall back to that if not milliseconds
75-
let dt = typeof timestamp === 'number' ? DateTime.fromMillis(timestamp) : DateTime.fromJSDate(timestamp);
75+
let dt = typeof timestamp === 'number' ? DateTime.fromMillis(timestamp) : DateTime.fromJSDate(new Date(timestamp));
7676
let value = dt.toFormat('yyyy/MM/dd HH:mm:ss');
7777
row.push(value);
7878
}

tests/index-test.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ describe('displayRevisions plugin', function() {
164164
},
165165
revisions: [
166166
{ revision: "rev:abcdef", timestamp: 1438232435000, deployer: "My Hamster"},
167-
{ revision: "rev:defghi", timestamp: 1032123125000, deployer: "My Hamster", active: true},
168-
{ revision: "rev:jklmno", timestamp: 1032123128000, deployer: "My Hamster"},
167+
{ revision: "rev:defghi", timestamp: '2002-09-15T20:52:05.000Z', deployer: "My Hamster", active: true},
168+
{ revision: "rev:jklmno", timestamp: new Date(1032123128000), deployer: "My Hamster"},
169169
{ revision: "rev:qrstuv", timestamp: 1032123155000, deployer: "My Hamster"},
170170
{ revision: "rev:xyz123", timestamp: 1032123123000, deployer: "My Hamster"}
171171
]
@@ -198,7 +198,7 @@ describe('displayRevisions plugin', function() {
198198
assert.equal(messages.length, 0);
199199
});
200200

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

216+
it('transforms ISO string timestamps to human-readable dates (yyyy/MM/dd HH:mm:ss)', function() {
217+
plugin.displayRevisions(context);
218+
let expectedFormat = ('yyyy/MM/dd HH:mm:ss');
219+
let expectedDate = DateTime.fromISO('2002-09-15T20:52:05.000Z').toFormat(expectedFormat);
220+
221+
let messages = mockUi.messages.reduce(function(previous, current) {
222+
if (current.indexOf(expectedDate) !== -1) {
223+
previous.push(current);
224+
}
225+
226+
return previous;
227+
}, []);
228+
assert.equal(messages.length, 1);
229+
});
230+
231+
it('transforms JS Date object timestamps to human-readable dates (yyyy/MM/dd HH:mm:ss)', function() {
232+
plugin.displayRevisions(context);
233+
let expectedFormat = ('yyyy/MM/dd HH:mm:ss');
234+
let expectedDate = DateTime.fromJSDate(new Date(1032123128000)).toFormat(expectedFormat);
235+
236+
let messages = mockUi.messages.reduce(function(previous, current) {
237+
if (current.indexOf(expectedDate) !== -1) {
238+
previous.push(current);
239+
}
240+
241+
return previous;
242+
}, []);
243+
assert.equal(messages.length, 1);
244+
});
245+
216246
it('highlights the active revision', function() {
217247
plugin.displayRevisions(context);
218248
let messages = mockUi.messages.reduce(function(previous, current) {

0 commit comments

Comments
 (0)