account for timezone when using relative times

Co-authored-by: eledobleefe <laura.fernandez@grafana.com>
Co-authored-by: Joao Silva <joao.silva@grafana.com>
Co-authored-by: L-M-K-B <48948963+L-M-K-B@users.noreply.github.com>
Co-authored-by: joshhunt <josh@trtr.co>
Co-authored-by: tskarhed <1438972+tskarhed@users.noreply.github.com>
This commit is contained in:
Ashley Harrison
2023-08-29 11:46:16 +01:00
parent fe1563882a
commit 01a3078d64
3 changed files with 12 additions and 4 deletions
@@ -130,6 +130,12 @@ export const dateTimeForTimeZone = (
return toUtc(input, formatInput);
}
if (timezone && timezone !== 'browser') {
// TODO fix types here
//@ts-ignore
return moment.tz(dateTimeAsMoment(input), formatInput, timezone);
}
return dateTime(input, formatInput);
};
@@ -129,7 +129,7 @@ describe('TimePickerWithHistory', () => {
it('Should display handle timezones correctly', async () => {
const timeRange = getDefaultTimeRange();
render(<TimePickerWithHistory value={timeRange} {...props} {...{ timeZone: 'Eastern/Pacific' }} />);
render(<TimePickerWithHistory value={timeRange} {...props} {...{ timeZone: 'Asia/Tokyo' }} />);
await userEvent.click(screen.getByLabelText(/Time range selected/));
await clearAndType(getFromField(), '2022-12-10 00:00:00');
+5 -3
View File
@@ -1,6 +1,6 @@
import { isString as _isString } from 'lodash';
import { TimeRange, AppEvents, rangeUtil, dateMath, PanelModel as IPanelModel } from '@grafana/data';
import { TimeRange, AppEvents, rangeUtil, dateMath, PanelModel as IPanelModel, dateTimeAsMoment } from '@grafana/data';
import { getTemplateSrv } from '@grafana/runtime';
import appEvents from 'app/core/app_events';
import config from 'app/core/config';
@@ -126,11 +126,13 @@ export function applyPanelTimeOverrides(panel: PanelModel, timeRange: TimeRange)
}
if (_isString(timeRange.raw.from)) {
const timeFromDate = dateMath.parse(timeFromInfo.from)!;
const fromTimezone = dateTimeAsMoment(timeRange.from).tz();
const toTimezone = dateTimeAsMoment(timeRange.to).tz();
const timeFromDate = dateMath.parse(timeFromInfo.from, undefined, fromTimezone)!;
newTimeData.timeInfo = timeFromInfo.display;
newTimeData.timeRange = {
from: timeFromDate,
to: dateMath.parse(timeFromInfo.to)!,
to: dateMath.parse(timeFromInfo.to, undefined, toTimezone)!,
raw: {
from: timeFromInfo.from,
to: timeFromInfo.to,