mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 05:11:50 +08:00

* refactor(frontend): rename all @grafana/data/src imports to @grafana/data * feat(grafana-data): introduce internal entrypoint for sharing code only with grafana * feat(grafana-data): add test entrypoint for data test utils usage in core * refactor(frontend): update import paths to use grafana/data exports entrypoints * docs(grafana-data): update comment in internal/index.ts * refactor(frontend): prefer public namespaced exports over re-exporting via internal * chore(frontend): fix a couple more weird paths that typescript complains about
22 lines
813 B
TypeScript
22 lines
813 B
TypeScript
import { dateMath, dateTime, isDateTime, DateTime, TimeRange } from '@grafana/data';
|
|
import { TimeModel } from 'app/features/dashboard/state/TimeModel';
|
|
|
|
export const getTimeRange = (
|
|
time: { from: DateTime | string; to: DateTime | string },
|
|
timeModel?: TimeModel
|
|
): TimeRange => {
|
|
// make copies if they are moment (do not want to return out internal moment, because they are mutable!)
|
|
const raw = {
|
|
from: isDateTime(time.from) ? dateTime(time.from) : time.from,
|
|
to: isDateTime(time.to) ? dateTime(time.to) : time.to,
|
|
};
|
|
|
|
const timezone = timeModel ? timeModel.getTimezone() : undefined;
|
|
|
|
return {
|
|
from: dateMath.parse(raw.from, false, timezone, timeModel?.fiscalYearStartMonth)!,
|
|
to: dateMath.parse(raw.to, true, timezone, timeModel?.fiscalYearStartMonth)!,
|
|
raw: raw,
|
|
};
|
|
};
|