|
@@ -14,6 +14,7 @@ import { rawToTimeRange } from './time';
|
|
|
|
|
|
|
|
// Types
|
|
// Types
|
|
|
import { TimeRange, TimeOption, TimeZone, TIME_FORMAT, SelectableValue } from '@grafana/data';
|
|
import { TimeRange, TimeOption, TimeZone, TIME_FORMAT, SelectableValue } from '@grafana/data';
|
|
|
|
|
+import { isMathString } from '@grafana/data/src/utils/datemath';
|
|
|
|
|
|
|
|
export interface Props {
|
|
export interface Props {
|
|
|
value: TimeRange;
|
|
value: TimeRange;
|
|
@@ -123,13 +124,21 @@ export class TimePicker extends PureComponent<Props, State> {
|
|
|
const { isCustomOpen } = this.state;
|
|
const { isCustomOpen } = this.state;
|
|
|
const options = this.mapTimeOptionsToSelectableValues(selectTimeOptions);
|
|
const options = this.mapTimeOptionsToSelectableValues(selectTimeOptions);
|
|
|
const currentOption = options.find(item => isTimeOptionEqualToTimeRange(item.value, value));
|
|
const currentOption = options.find(item => isTimeOptionEqualToTimeRange(item.value, value));
|
|
|
- const rangeString = rangeUtil.describeTimeRange(value.raw);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const isUTC = timeZone === 'utc';
|
|
|
|
|
+ const adjustedTo = isUTC ? value.to.utc() : value.to.local();
|
|
|
|
|
+ const adjustedFrom = isUTC ? value.from.utc() : value.from.local();
|
|
|
|
|
+ const adjustedTimeRange = {
|
|
|
|
|
+ to: isMathString(value.raw.to) ? value.raw.to : adjustedTo,
|
|
|
|
|
+ from: isMathString(value.raw.from) ? value.raw.from : adjustedFrom,
|
|
|
|
|
+ };
|
|
|
|
|
+ const rangeString = rangeUtil.describeTimeRange(adjustedTimeRange);
|
|
|
|
|
|
|
|
const label = (
|
|
const label = (
|
|
|
<>
|
|
<>
|
|
|
{isCustomOpen && <span>Custom time range</span>}
|
|
{isCustomOpen && <span>Custom time range</span>}
|
|
|
{!isCustomOpen && <span>{rangeString}</span>}
|
|
{!isCustomOpen && <span>{rangeString}</span>}
|
|
|
- {timeZone === 'utc' && <span className="time-picker-utc">UTC</span>}
|
|
|
|
|
|
|
+ {isUTC && <span className="time-picker-utc">UTC</span>}
|
|
|
</>
|
|
</>
|
|
|
);
|
|
);
|
|
|
const isAbsolute = isDateTime(value.raw.to);
|
|
const isAbsolute = isDateTime(value.raw.to);
|