Skip to content

Commit f866385

Browse files
[APM] Adjust time formats based on the difference between start and end (#84470) (#84496)
1 parent a55f3e0 commit f866385

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

x-pack/plugins/apm/common/utils/formatters/datetime.test.ts

+22-4
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,37 @@ describe('date time formatters', () => {
7373
const dateRange = asRelativeDateTimeRange(start, end);
7474
expect(dateRange).toEqual('Oct 29, 2019, 10:01 - 15:01 (UTC+1)');
7575
});
76-
});
77-
describe('MMM D, YYYY, HH:mm:ss - HH:mm:ss (UTC)', () => {
7876
it('range: 14 minutes', () => {
7977
const start = formatDateToTimezone('2019-10-29 10:01:01');
8078
const end = formatDateToTimezone('2019-10-29 10:15:01');
8179
const dateRange = asRelativeDateTimeRange(start, end);
82-
expect(dateRange).toEqual('Oct 29, 2019, 10:01:01 - 10:15:01 (UTC+1)');
80+
expect(dateRange).toEqual('Oct 29, 2019, 10:01 - 10:15 (UTC+1)');
8381
});
8482
it('range: 5 minutes', () => {
8583
const start = formatDateToTimezone('2019-10-29 10:01:01');
8684
const end = formatDateToTimezone('2019-10-29 10:06:01');
8785
const dateRange = asRelativeDateTimeRange(start, end);
88-
expect(dateRange).toEqual('Oct 29, 2019, 10:01:01 - 10:06:01 (UTC+1)');
86+
expect(dateRange).toEqual('Oct 29, 2019, 10:01 - 10:06 (UTC+1)');
87+
});
88+
it('range: 1 minute', () => {
89+
const start = formatDateToTimezone('2019-10-29 10:01:01');
90+
const end = formatDateToTimezone('2019-10-29 10:02:01');
91+
const dateRange = asRelativeDateTimeRange(start, end);
92+
expect(dateRange).toEqual('Oct 29, 2019, 10:01 - 10:02 (UTC+1)');
93+
});
94+
});
95+
describe('MMM D, YYYY, HH:mm:ss - HH:mm:ss (UTC)', () => {
96+
it('range: 50 seconds', () => {
97+
const start = formatDateToTimezone('2019-10-29 10:01:01');
98+
const end = formatDateToTimezone('2019-10-29 10:01:50');
99+
const dateRange = asRelativeDateTimeRange(start, end);
100+
expect(dateRange).toEqual('Oct 29, 2019, 10:01:01 - 10:01:50 (UTC+1)');
101+
});
102+
it('range: 10 seconds', () => {
103+
const start = formatDateToTimezone('2019-10-29 10:01:01');
104+
const end = formatDateToTimezone('2019-10-29 10:01:11');
105+
const dateRange = asRelativeDateTimeRange(start, end);
106+
expect(dateRange).toEqual('Oct 29, 2019, 10:01:01 - 10:01:11 (UTC+1)');
89107
});
90108
});
91109
describe('MMM D, YYYY, HH:mm:ss.SSS - HH:mm:ss.SSS (UTC)', () => {

x-pack/plugins/apm/common/utils/formatters/datetime.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ function getFormatsAccordingToDateDifference(
8080
return { dateFormat: dateFormatWithDays };
8181
}
8282

83-
if (getDateDifference(start, end, 'hours') >= 5) {
83+
if (getDateDifference(start, end, 'minutes') >= 1) {
8484
return {
8585
dateFormat: dateFormatWithDays,
8686
timeFormat: getTimeFormat('minutes'),
8787
};
8888
}
8989

90-
if (getDateDifference(start, end, 'minutes') >= 5) {
90+
if (getDateDifference(start, end, 'seconds') >= 10) {
9191
return {
9292
dateFormat: dateFormatWithDays,
9393
timeFormat: getTimeFormat('seconds'),
@@ -121,8 +121,8 @@ export function asAbsoluteDateTime(
121121
* | >= 5 years | YYYY - YYYY |
122122
* | >= 5 months | MMM YYYY - MMM YYYY |
123123
* | > 1 day | MMM D, YYYY - MMM D, YYYY |
124-
* | >= 5 hours | MMM D, YYYY, HH:mm - HH:mm (UTC) |
125-
* | >= 5 minutes | MMM D, YYYY, HH:mm:ss - HH:mm:ss (UTC) |
124+
* | >= 1 minute | MMM D, YYYY, HH:mm - HH:mm (UTC) |
125+
* | >= 10 seconds | MMM D, YYYY, HH:mm:ss - HH:mm:ss (UTC) |
126126
* | default | MMM D, YYYY, HH:mm:ss.SSS - HH:mm:ss.SSS (UTC) |
127127
*
128128
* @param start timestamp

0 commit comments

Comments
 (0)