mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
Merge pull request #14510 from grafana/14484-table-format-string-epochs
In Table Panel, renders epoch string as date if date column style
This commit is contained in:
commit
e80a287f7a
@ -91,7 +91,14 @@ export class TableRenderer {
|
|||||||
if (_.isArray(v)) {
|
if (_.isArray(v)) {
|
||||||
v = v[0];
|
v = v[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if is an epoch (numeric string and len > 12)
|
||||||
|
if (_.isString(v) && !isNaN(v) && v.length > 12) {
|
||||||
|
v = parseInt(v, 10);
|
||||||
|
}
|
||||||
|
|
||||||
let date = moment(v);
|
let date = moment(v);
|
||||||
|
|
||||||
if (this.isUtc) {
|
if (this.isUtc) {
|
||||||
date = date.utc();
|
date = date.utc();
|
||||||
}
|
}
|
||||||
|
@ -186,6 +186,21 @@ describe('when rendering table', () => {
|
|||||||
expect(html).toBe('<td>2014-01-01T06:06:06Z</td>');
|
expect(html).toBe('<td>2014-01-01T06:06:06Z</td>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('time column with epoch as string should be formatted', () => {
|
||||||
|
const html = renderer.renderCell(0, 0, '1388556366666');
|
||||||
|
expect(html).toBe('<td>2014-01-01T06:06:06Z</td>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('time column with RFC2822 date as string should be formatted', () => {
|
||||||
|
const html = renderer.renderCell(0, 0, 'Sat, 01 Dec 2018 01:00:00 GMT');
|
||||||
|
expect(html).toBe('<td>2018-12-01T01:00:00Z</td>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('time column with ISO date as string should be formatted', () => {
|
||||||
|
const html = renderer.renderCell(0, 0, '2018-12-01T01:00:00Z');
|
||||||
|
expect(html).toBe('<td>2018-12-01T01:00:00Z</td>');
|
||||||
|
});
|
||||||
|
|
||||||
it('undefined time column should be rendered as -', () => {
|
it('undefined time column should be rendered as -', () => {
|
||||||
const html = renderer.renderCell(0, 0, undefined);
|
const html = renderer.renderCell(0, 0, undefined);
|
||||||
expect(html).toBe('<td>-</td>');
|
expect(html).toBe('<td>-</td>');
|
||||||
|
Loading…
Reference in New Issue
Block a user