Skip to content

Commit

Permalink
Table visualization: accept timestamp for date/time columns
Browse files Browse the repository at this point in the history
  • Loading branch information
kravets-levko committed Nov 23, 2019
1 parent 4d1b359 commit 3013f34
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 3013f34

Please sign in to comment.