Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table visualization: accept timestamp for date/time columns #4389

Merged
merged 3 commits into from
Nov 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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