diff --git a/x-pack/legacy/plugins/monitoring/public/views/__tests__/base_controller.js b/x-pack/legacy/plugins/monitoring/public/views/__tests__/base_controller.js index 4523c5db58464..e25586152a47b 100644 --- a/x-pack/legacy/plugins/monitoring/public/views/__tests__/base_controller.js +++ b/x-pack/legacy/plugins/monitoring/public/views/__tests__/base_controller.js @@ -21,6 +21,7 @@ describe('MonitoringViewBaseController', function () { let opts; let titleService; let executorService; + let configService; const httpCall = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms)); before(() => { @@ -29,6 +30,9 @@ describe('MonitoringViewBaseController', function () { register: spy(), start: spy() }; + configService = { + get: spy() + }; const windowMock = () => { const events = {}; @@ -47,6 +51,7 @@ describe('MonitoringViewBaseController', function () { injectorGetStub.withArgs('$executor').returns(executorService); injectorGetStub.withArgs('localStorage').throws('localStorage should not be used by this class'); injectorGetStub.withArgs('$window').returns(windowMock()); + injectorGetStub.withArgs('config').returns(configService); $injector = { get: injectorGetStub }; $scope = { diff --git a/x-pack/legacy/plugins/monitoring/public/views/base_controller.js b/x-pack/legacy/plugins/monitoring/public/views/base_controller.js index 600e229b031bf..830fd80629585 100644 --- a/x-pack/legacy/plugins/monitoring/public/views/base_controller.js +++ b/x-pack/legacy/plugins/monitoring/public/views/base_controller.js @@ -14,6 +14,21 @@ import { I18nContext } from 'ui/i18n'; import { PromiseWithCancel } from '../../common/cancel_promise'; import { updateSetupModeData, getSetupModeState } from '../lib/setup_mode'; +/** + * Given a timezone, this function will calculate the offset in milliseconds + * from UTC time. + * + * @param {string} timezone + */ +const getOffsetInMS = (timezone) => { + if (timezone === 'Browser') { + return 0; + } + const offsetInMinutes = moment.tz(timezone).utcOffset(); + const offsetInMS = offsetInMinutes * 1 * 60 * 1000; + return offsetInMS; +}; + /** * Class to manage common instantiation behaviors in a view controller * @@ -76,6 +91,7 @@ export class MonitoringViewBaseController { const titleService = $injector.get('title'); const $executor = $injector.get('$executor'); const $window = $injector.get('$window'); + const config = $injector.get('config'); titleService($scope.cluster, title); @@ -152,9 +168,11 @@ export class MonitoringViewBaseController { this.onBrush = ({ xaxis }) => { removePopstateHandler(); const { to, from } = xaxis; + const timezone = config.get('dateFormat:tz'); + const offset = getOffsetInMS(timezone); timefilter.setTime({ - from: moment(from), - to: moment(to), + from: moment(from - offset), + to: moment(to - offset), mode: 'absolute' }); ++zoomInLevel;