fix Moment.js timezone error when defining a range filter (#143213)

This commit is contained in:
Anton Dosov 2022-10-17 12:18:56 +02:00 committed by GitHub
parent 9782417578
commit 891e587571
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,12 +37,13 @@ export function isRangeParams(params: any): params is RangeParams {
function RangeValueInputUI(props: Props) {
const kibana = useKibana();
const tzConfig = kibana.services.uiSettings!.get('dateFormat:tz');
const formatDateChange = (value: string | number | boolean) => {
if (typeof value !== 'string' && typeof value !== 'number') return value;
const momentParsedValue = moment(value).tz(tzConfig);
const tzConfig = kibana.services.uiSettings!.get('dateFormat:tz');
const tz = !tzConfig || tzConfig === 'Browser' ? moment.tz.guess() : tzConfig;
const momentParsedValue = moment(value).tz(tz);
if (momentParsedValue.isValid()) return momentParsedValue?.format('YYYY-MM-DDTHH:mm:ss.SSSZ');
return value;