[Timefilter] Convert to ISO string instead of JS string (#47722) (#47950)

* Convert to ISO string instead of JS string

* Add test
This commit is contained in:
Chris Roberson 2019-10-11 13:23:23 -04:00 committed by GitHub
parent 6f7814b1c3
commit 7b620aba96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 1 deletions

View file

@ -0,0 +1,53 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { registerTimefilterWithGlobalState } from './setup_router';
jest.mock('ui/utils/subscribe_with_scope', () => ({
subscribeWithScope: jest.fn()
}));
describe('registerTimefilterWithGlobalState()', () => {
it('should always use iso8601 strings', async () => {
const setTime = jest.fn();
const timefilter = {
setTime,
setRefreshInterval: jest.fn(),
getRefreshIntervalUpdate$: jest.fn(),
getTimeUpdate$: jest.fn()
};
const globalState = {
time: {
from: '2017-09-07T20:12:04.011Z',
to: '2017-09-07T20:18:55.733Z',
},
on: (eventName, callback) => {
callback();
}
};
registerTimefilterWithGlobalState(
timefilter,
globalState
);
expect(setTime.mock.calls.length).toBe(2);
expect(setTime.mock.calls[1][0]).toEqual(globalState.time);
});
});

View file

@ -30,7 +30,7 @@ import { TimefilterContract } from '../../../core_plugins/data/public/timefilter
// and listener can be registered without angular.
function convertISO8601(stringTime: string): string {
const obj = moment(stringTime, 'YYYY-MM-DDTHH:mm:ss.SSSZ', true);
return obj.isValid() ? obj.toString() : stringTime;
return obj.isValid() ? obj.toISOString() : stringTime;
}
export function getTimefilterConfig() {