diff --git a/x-pack/plugins/ml/public/jobs/jobs_list/components/job_actions/results.js b/x-pack/plugins/ml/public/jobs/jobs_list/components/job_actions/results.js index 3565f510645d..05e1db798907 100644 --- a/x-pack/plugins/ml/public/jobs/jobs_list/components/job_actions/results.js +++ b/x-pack/plugins/ml/public/jobs/jobs_list/components/job_actions/results.js @@ -14,6 +14,8 @@ import { } from '@elastic/eui'; import chrome from 'ui/chrome'; +import moment from 'moment'; +const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'; import { mlJobService } from 'plugins/ml/services/job_service'; @@ -21,22 +23,18 @@ function getLink(location, jobs) { let from = 0; let to = 0; if (jobs.length === 1) { - from = jobs[0].earliestTimeStamp.string; - to = jobs[0].latestTimeStamp.string; + from = jobs[0].earliestTimestampMs; + to = jobs[0].latestTimestampMs; } else { - const froms = jobs.map(j => j.earliestTimeStamp).sort((a, b) => a.unix > b.unix); - const tos = jobs.map(j => j.latestTimeStamp).sort((a, b) => a.unix < b.unix); - from = froms[0].string; - to = tos[0].string; + from = Math.min(...jobs.map(j => j.earliestTimestampMs)); + to = Math.max(...jobs.map(j => j.latestTimestampMs)); } - // if either of the dates are empty, set them to undefined - // moment will convert undefined to now. - from = (from === '') ? undefined : from; - to = (to === '') ? undefined : to; + const fromString = moment(from).format(TIME_FORMAT); + const toString = moment(to).format(TIME_FORMAT); const jobIds = jobs.map(j => j.id); - const url = mlJobService.createResultsUrl(jobIds, from, to, location); + const url = mlJobService.createResultsUrl(jobIds, fromString, toString, location); return `${chrome.getBasePath()}/app/${url}`; } diff --git a/x-pack/plugins/ml/public/jobs/jobs_list/components/jobs_list/jobs_list.js b/x-pack/plugins/ml/public/jobs/jobs_list/components/jobs_list/jobs_list.js index 9898cfb0c751..7687ac372308 100644 --- a/x-pack/plugins/ml/public/jobs/jobs_list/components/jobs_list/jobs_list.js +++ b/x-pack/plugins/ml/public/jobs/jobs_list/components/jobs_list/jobs_list.js @@ -11,6 +11,7 @@ import React, { } from 'react'; import { sortBy } from 'lodash'; +import moment from 'moment'; import { toLocaleString } from '../../../../util/string_utils'; import { ResultLinks, actionsMenuContent } from '../job_actions'; @@ -25,6 +26,7 @@ import { const PAGE_SIZE = 10; const PAGE_SIZE_OPTIONS = [10, 25, 50]; +const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'; export class JobsList extends Component { constructor(props) { @@ -157,11 +159,13 @@ export class JobsList extends Component { }, { name: 'Latest timestamp', truncateText: false, - field: 'latestTimeStampUnix', + field: 'latestTimeStampSortValue', sortable: true, render: (time, item) => ( - { item.latestTimeStamp.string } + { + (item.latestTimestampMs === undefined) ? '' : moment(item.latestTimestampMs).format(TIME_FORMAT) + } ) }, { diff --git a/x-pack/plugins/ml/public/jobs/jobs_list/components/jobs_list_view/jobs_list_view.js b/x-pack/plugins/ml/public/jobs/jobs_list/components/jobs_list_view/jobs_list_view.js index 8205c75da9e3..d5594933cf86 100644 --- a/x-pack/plugins/ml/public/jobs/jobs_list/components/jobs_list_view/jobs_list_view.js +++ b/x-pack/plugins/ml/public/jobs/jobs_list/components/jobs_list_view/jobs_list_view.js @@ -240,7 +240,7 @@ export class JobsListView extends Component { fullJobsList[job.id] = job.fullJob; delete job.fullJob; } - job.latestTimeStampUnix = job.latestTimeStamp.unix; + job.latestTimeStampSortValue = (job.latestTimeStampMs || 0); return job; }); const filteredJobsSummaryList = filterJobs(jobsSummaryList, this.state.filterClauses); diff --git a/x-pack/plugins/ml/public/jobs/jobs_list/components/start_datafeed_modal/start_datafeed_modal.js b/x-pack/plugins/ml/public/jobs/jobs_list/components/start_datafeed_modal/start_datafeed_modal.js index c22a7aeec192..cd5a939cbba1 100644 --- a/x-pack/plugins/ml/public/jobs/jobs_list/components/start_datafeed_modal/start_datafeed_modal.js +++ b/x-pack/plugins/ml/public/jobs/jobs_list/components/start_datafeed_modal/start_datafeed_modal.js @@ -196,6 +196,6 @@ StartDatafeedModal.propTypes = { }; function getLowestLatestTime(jobs) { - const times = jobs.map(j => j.latestTimeStamp.unix.valueOf()); + const times = jobs.map(j => j.latestTimeStampSortValue); return moment(Math.min(...times)); } diff --git a/x-pack/plugins/ml/server/models/job_service/jobs.js b/x-pack/plugins/ml/server/models/job_service/jobs.js index 6a9da9ff5b75..2cb43bdabc99 100644 --- a/x-pack/plugins/ml/server/models/job_service/jobs.js +++ b/x-pack/plugins/ml/server/models/job_service/jobs.js @@ -13,8 +13,6 @@ import { fillResultsWithTimeouts, isRequestTimeout } from './error_utils'; import moment from 'moment'; import { uniq } from 'lodash'; -const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'; - export function jobsProvider(callWithRequest) { const { forceDeleteDatafeed, getDatafeedIdsByJobId } = datafeedsProvider(callWithRequest); @@ -99,8 +97,8 @@ export function jobsProvider(callWithRequest) { const jobs = fullJobsList.map((job) => { const hasDatafeed = (typeof job.datafeed_config === 'object' && Object.keys(job.datafeed_config).length); const { - earliest: earliestTimeStamp, - latest: latestTimeStamp } = earliestAndLatestTimeStamps(job.data_counts); + earliest: earliestTimestampMs, + latest: latestTimestampMs } = earliestAndLatestTimeStamps(job.data_counts); const tempJob = { id: job.job_id, @@ -112,8 +110,8 @@ export function jobsProvider(callWithRequest) { hasDatafeed, datafeedId: (hasDatafeed && job.datafeed_config.datafeed_id) ? job.datafeed_config.datafeed_id : '', datafeedState: (hasDatafeed && job.datafeed_config.state) ? job.datafeed_config.state : '', - latestTimeStamp, - earliestTimeStamp, + latestTimestampMs, + earliestTimestampMs, nodeName: (job.node) ? job.node.name : undefined, }; if (jobIds.find(j => (j === tempJob.id))) { @@ -243,22 +241,16 @@ export function jobsProvider(callWithRequest) { function earliestAndLatestTimeStamps(dataCounts) { const obj = { - earliest: { string: '', unix: 0 }, - latest: { string: '', unix: 0 }, + earliest: undefined, + latest: undefined, }; if (dataCounts.earliest_record_timestamp) { - const ts = moment(dataCounts.earliest_record_timestamp); - obj.earliest.string = ts.format(TIME_FORMAT); - obj.earliest.unix = ts.valueOf(); - obj.earliest.moment = ts; + obj.earliest = moment(dataCounts.earliest_record_timestamp).valueOf(); } if (dataCounts.latest_record_timestamp) { - const ts = moment(dataCounts.latest_record_timestamp); - obj.latest.string = ts.format(TIME_FORMAT); - obj.latest.unix = ts.valueOf(); - obj.latest.moment = ts; + obj.latest = moment(dataCounts.latest_record_timestamp).valueOf(); } return obj;