Skip to content

Commit

Permalink
refactor: add func for get current time range
Browse files Browse the repository at this point in the history
  • Loading branch information
Loori-R committed Jul 10, 2023
1 parent d7f2a97 commit ad672f1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/services/TimeSrv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export const getTimeRange = (
};
};

const getCurrentTimeRange = (): RawTimeRange => {
return getTemplateSrv()?.timeRange?.raw || getDefaultTimeRange().raw;
}

export interface TimeModel {
time: any;
fiscalYearStartMonth?: number;
Expand All @@ -89,7 +93,7 @@ export class TimeSrv {
private autoRefreshBlocked?: boolean;

constructor(private contextSrv: ContextSrv) {
this.time = getTemplateSrv()?.timeRange?.raw || getDefaultTimeRange().raw;
this.time = getCurrentTimeRange()
this.refreshTimeModel = this.refreshTimeModel.bind(this);

appEvents.subscribe(ZoomOutEvent, (e) => {
Expand Down Expand Up @@ -383,8 +387,7 @@ export class TimeSrv {
};

timeRange(): TimeRange {
const time = getTemplateSrv()?.timeRange?.raw || getDefaultTimeRange().raw;
return getTimeRange(time, this.timeModel)
return getTimeRange(getCurrentTimeRange(), this.timeModel)
}

zoomOut(factor: number, updateUrl = true) {
Expand Down

0 comments on commit ad672f1

Please sign in to comment.