Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

1.2 KB
Raw Blame
import { PANEL_TYPES } from 'constants/queryBuilder';
import { timePreferenceType } from 'constants/timePreference';
import {
	CustomTimeType,
	Time,
} from 'container/TopNav/DateTimeSelectionV2/types';
import store from 'store';

import getMaxMinTime from './getMaxMinTime';
import getMinMax from './getMinMax';
import getStartAndEndTime from './getStartAndEndTime';

const getStartEndRangeTime = ({
	type = 'GLOBAL_TIME',
	graphType = null,
	interval = 'custom',
}: GetStartEndRangeTimesProps): GetStartEndRangeTimesPayload => {
	const { globalTime } = store.getState();

	const minMax = getMinMax(interval, [
		globalTime.minTime / 1000000,
		globalTime.maxTime / 1000000,
	]);

	const maxMinTime = getMaxMinTime({
		graphType,
		maxTime: minMax.maxTime,
		minTime: minMax.minTime,
	});

	const { end, start } = getStartAndEndTime({
		type,
		maxTime: maxMinTime.maxTime,
		minTime: maxMinTime.minTime,
	});

	return { start, end };
};

interface GetStartEndRangeTimesProps {
	type?: timePreferenceType;
	graphType?: PANEL_TYPES | null;
	interval?: Time | CustomTimeType;
}

interface GetStartEndRangeTimesPayload {
	start: string;
	end: string;
}

export default getStartEndRangeTime;