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

[CSV export] date values formatted properly #29781

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export function createDateFormat(FieldFormat) {
return '-';
}

const date = moment(val);
const date = moment.utc(val); // All dates returned by ES are UTC
if (date.isValid()) {
return date.format(pattern);
return date.tz(this._timeZone).format(pattern);
} else {
return val;
}
Expand Down
18 changes: 8 additions & 10 deletions x-pack/plugins/reporting/export_types/csv/server/execute_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ function executeJobFn(server) {
const fieldFormats = await server.fieldFormatServiceFactory(uiSettings);
const formatsMap = fieldFormatMapFactory(indexPatternSavedObject, fieldFormats);

const separator = await uiSettings.get('csv:separator');
const quoteValues = await uiSettings.get('csv:quoteValues');
const maxSizeBytes = config.get('xpack.reporting.csv.maxSizeBytes');
const scroll = config.get('xpack.reporting.csv.scroll');
const settings = {
separator: await uiSettings.get('csv:separator'),
quoteValues: await uiSettings.get('csv:quoteValues'),
maxSizeBytes: config.get('xpack.reporting.csv.maxSizeBytes'),
scroll: config.get('xpack.reporting.csv.scroll'),
timezone: await uiSettings.get('dateFormat:tz'),
};

const { content, maxSizeReached, size } = await generateCsv({
searchRequest,
Expand All @@ -73,12 +76,7 @@ function executeJobFn(server) {
conflictedTypesFields,
callEndpoint,
cancellationToken,
settings: {
separator,
quoteValues,
maxSizeBytes,
scroll
}
settings,
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ import { isObject, isNull, isUndefined } from 'lodash';

export function createFormatCsvValues(escapeValue, separator, fields, formatsMap) {
return function formatCsvValues(values) {
return fields.map((field) => {
let value = values[field];
return fields
.map(field => {
const value = values[field];
if (isNull(value) || isUndefined(value)) {
return '';
}

if (isNull(value) || isUndefined(value)) {
return '';
}
let formattedValue = value;
if (formatsMap.has(field)) {
const formatter = formatsMap.get(field);
formattedValue = formatter.convert(value);
}

if (formatsMap.has(field)) {
const formatter = formatsMap.get(field);
value = formatter.convert(value);
}

if (isObject(value)) {
return JSON.stringify(value);
}

return value.toString();
})
return formattedValue;
})
.map(value => (isObject(value) ? JSON.stringify(value) : value))
.map(value => value.toString())
.map(escapeValue)
.join(separator);
};
Expand Down