Skip to content
Merged
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 @@ -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(() => {
Expand All @@ -29,6 +30,9 @@ describe('MonitoringViewBaseController', function () {
register: spy(),
start: spy()
};
configService = {
get: spy()
};

const windowMock = () => {
const events = {};
Expand All @@ -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 = {
Expand Down
22 changes: 20 additions & 2 deletions x-pack/legacy/plugins/monitoring/public/views/base_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of nitpick, but I think timezone and offset can be calculated just once in the constructor, unless config.get always gets the latest/updated value

timefilter.setTime({
from: moment(from),
to: moment(to),
from: moment(from - offset),
to: moment(to - offset),
mode: 'absolute'
});
++zoomInLevel;
Expand Down