Skip to content

Commit

Permalink
Table visualization: accept timestamp for date/time columns (#4389)
Browse files Browse the repository at this point in the history
  • Loading branch information
kravets-levko authored Nov 24, 2019
1 parent a7a9339 commit e72d7a8
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions client/app/lib/value-format.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import moment from 'moment/moment';
import numeral from 'numeral';
import { isString, isArray, isUndefined, isNil, toString } from 'lodash';
import { isString, isArray, isUndefined, isFinite, isNil, toString } from 'lodash';

numeral.options.scalePercentBy100 = false;

Expand All @@ -21,13 +21,22 @@ export function createTextFormatter(highlightLinks) {
return value => toString(value);
}

function toMoment(value) {
if (moment.isMoment(value)) {
return value;
}
if (isFinite(value)) {
return moment(value);
}
// same as default `moment(value)`, but avoid fallback to `new Date()`
return moment(toString(value), [moment.ISO_8601, moment.RFC_2822]);
}

export function createDateTimeFormatter(format) {
if (isString(format) && (format !== '')) {
return (value) => {
if (value && moment.isMoment(value)) {
return value.format(format);
}
return toString(value);
const wrapped = toMoment(value);
return wrapped.isValid() ? wrapped.format(format) : toString(value);
};
}
return value => toString(value);
Expand Down

0 comments on commit e72d7a8

Please sign in to comment.