Explore: Fixes incorrect handling of utc in timeEpic (#18386)

* Fix: Fixes incorrect handling of utc in timeEpic

* Chore: Renames dateTimeFromTimeZone to dateTimeForTimeZone
This commit is contained in:
Hugo Häggmark
2019-08-06 10:43:53 +02:00
committed by GitHub
parent cbfdac43d8
commit ead2d6e88f
8 changed files with 34 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
import includes from 'lodash/includes';
import isDate from 'lodash/isDate';
import { DateTime, dateTime, toUtc, ISO_8601, isDateTime, DurationUnit } from './moment_wrapper';
import { DateTime, dateTime, dateTimeForTimeZone, ISO_8601, isDateTime, DurationUnit } from './moment_wrapper';
import { TimeZone } from '../types';
const units: DurationUnit[] = ['y', 'M', 'w', 'd', 'h', 'm', 's'];
@@ -45,11 +45,7 @@ export function parse(text: string | DateTime | Date, roundUp?: boolean, timezon
let parseString;
if (text.substring(0, 3) === 'now') {
if (timezone === 'utc') {
time = toUtc();
} else {
time = dateTime();
}
time = dateTimeForTimeZone(timezone);
mathString = text.substring('now'.length);
} else {
index = text.indexOf('||');

View File

@@ -1,3 +1,4 @@
import { TimeZone } from '../types/time';
/* tslint:disable:import-blacklist ban ban-types */
import moment, { MomentInput, DurationInputArg1 } from 'moment';
@@ -96,3 +97,15 @@ export const toDuration = (input?: DurationInput, unit?: DurationUnit): DateTime
export const dateTime = (input?: DateTimeInput, formatInput?: FormatInput): DateTime => {
return moment(input as MomentInput, formatInput) as DateTime;
};
export const dateTimeForTimeZone = (
timezone?: TimeZone,
input?: DateTimeInput,
formatInput?: FormatInput
): DateTime => {
if (timezone === 'utc') {
return toUtc(input, formatInput);
}
return dateTime(input, formatInput);
};