forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] x-axis labels on Error occurrences chart are incorrect based on…
… Kibana timezone (elastic#55686) * adjusting x-axis to use kibana timezone * adjusting x-axis to use kibana timezone * refactoring
- Loading branch information
1 parent
a0529f7
commit ea746d2
Showing
5 changed files
with
137 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
x-pack/legacy/plugins/apm/public/components/shared/charts/helper/__test__/timezone.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import moment from 'moment-timezone'; | ||
import { getDomainTZ, getTimeTicksTZ } from '../timezone'; | ||
|
||
describe('Timezone helper', () => { | ||
let originalTimezone: moment.MomentZone | null; | ||
const min = new Date('Tue Jan 28 2020 05:36:00 GMT+0100').valueOf(); | ||
const max = new Date('Wed Jan 29 2020 07:12:00 GMT+0100').valueOf(); | ||
|
||
afterAll(() => { | ||
moment.tz.setDefault(originalTimezone ? originalTimezone.name : ''); | ||
}); | ||
describe('getTimeTicksTZ', () => { | ||
it('returns ticks when in Ameca/New_York timezone', () => { | ||
moment.tz.setDefault('America/New_York'); | ||
expect( | ||
getTimeTicksTZ({ domain: [min, max], totalTicks: 8, width: 1138 }) | ||
).toEqual([ | ||
new Date('2020-01-28T11:00:00.000Z'), | ||
new Date('2020-01-28T14:00:00.000Z'), | ||
new Date('2020-01-28T17:00:00.000Z'), | ||
new Date('2020-01-28T20:00:00.000Z'), | ||
new Date('2020-01-28T23:00:00.000Z'), | ||
new Date('2020-01-29T02:00:00.000Z'), | ||
new Date('2020-01-29T05:00:00.000Z'), | ||
new Date('2020-01-29T08:00:00.000Z'), | ||
new Date('2020-01-29T11:00:00.000Z') | ||
]); | ||
}); | ||
it('returns ticks when in Europe/Amsterdam timezone', () => { | ||
moment.tz.setDefault('Europe/Amsterdam'); | ||
expect( | ||
getTimeTicksTZ({ domain: [min, max], totalTicks: 8, width: 1138 }) | ||
).toEqual([ | ||
new Date('2020-01-28T05:00:00.000Z'), | ||
new Date('2020-01-28T08:00:00.000Z'), | ||
new Date('2020-01-28T11:00:00.000Z'), | ||
new Date('2020-01-28T14:00:00.000Z'), | ||
new Date('2020-01-28T17:00:00.000Z'), | ||
new Date('2020-01-28T20:00:00.000Z'), | ||
new Date('2020-01-28T23:00:00.000Z'), | ||
new Date('2020-01-29T02:00:00.000Z'), | ||
new Date('2020-01-29T05:00:00.000Z') | ||
]); | ||
}); | ||
}); | ||
|
||
describe('getDomainTZ', () => { | ||
it('returns domain when in Ameca/New_York timezone', () => { | ||
moment.tz.setDefault('America/New_York'); | ||
expect(getDomainTZ(min, max)).toEqual([ | ||
new Date('Tue Jan 28 2020 00:36:00 GMT+0100').valueOf(), | ||
new Date('Wed Jan 29 2020 02:12:00 GMT+0100').valueOf() | ||
]); | ||
}); | ||
it('returns domain when in Europe/Amsterdam timezone', () => { | ||
moment.tz.setDefault('Europe/Amsterdam'); | ||
expect(getDomainTZ(min, max)).toEqual([ | ||
new Date('Tue Jan 28 2020 06:36:00 GMT+0100').valueOf(), | ||
new Date('Wed Jan 29 2020 08:12:00 GMT+0100').valueOf() | ||
]); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
x-pack/legacy/plugins/apm/public/components/shared/charts/helper/timezone.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import d3 from 'd3'; | ||
import { getTimezoneOffsetInMs } from '../CustomPlot/getTimezoneOffsetInMs'; | ||
|
||
interface Params { | ||
domain: [number, number]; | ||
totalTicks: number; | ||
width: number; | ||
} | ||
|
||
export const getTimeTicksTZ = ({ domain, totalTicks, width }: Params) => | ||
d3.time.scale | ||
.utc() | ||
.domain(domain) | ||
.range([0, width]) | ||
.ticks(totalTicks) | ||
.map(x => { | ||
const time = x.getTime(); | ||
return new Date(time + getTimezoneOffsetInMs(time)); | ||
}); | ||
|
||
export const getDomainTZ = (min: number, max: number): [number, number] => { | ||
const [xMinZone, xMaxZone] = [min, max].map( | ||
time => time - getTimezoneOffsetInMs(time) | ||
); | ||
return [xMinZone, xMaxZone]; | ||
}; |