MCPcopy
hub / github.com/umami-software/umami / useDateRange

Function useDateRange

src/components/hooks/useDateRange.ts:8–38  ·  view source on GitHub ↗
(options: { ignoreOffset?: boolean; timezone?: string } = {})

Source from the content-addressed store, hash-verified

6import { getItem } from '@/lib/storage';
7
8export function useDateRange(options: { ignoreOffset?: boolean; timezone?: string } = {}) {
9 const {
10 query: { date = '', unit = '', offset = 0, compare = 'prev' },
11 } = useNavigation();
12 const { locale } = useLocale();
13 const dateRange = useMemo(() => {
14 const dateRangeObject = parseDateRange(
15 date || getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE_VALUE,
16 unit,
17 locale,
18 options.timezone,
19 );
20
21 return !options.ignoreOffset && offset
22 ? getOffsetDateRange(dateRangeObject, +offset)
23 : dateRangeObject;
24 }, [date, unit, offset, options]);
25
26 const dateCompare = getCompareDate(compare, dateRange.startDate, dateRange.endDate);
27
28 return {
29 date,
30 unit,
31 offset,
32 compare,
33 isAllTime: date.endsWith(`:all`),
34 isCustomRange: date.startsWith('range:'),
35 dateRange,
36 dateCompare,
37 };
38}

Callers 15

EventsChartFunction · 0.90
PropertyChartFunction · 0.90
PropertyNumericChartFunction · 0.90
useDateParametersFunction · 0.90
MonthFilterFunction · 0.90
RefreshButtonFunction · 0.90
WebsiteDateFilterFunction · 0.90
PixelMetricsBarFunction · 0.90
WebsiteMetricsBarFunction · 0.90
WebsiteChartFunction · 0.90
JourneysPageFunction · 0.90
BreakdownPageFunction · 0.90

Calls 6

useNavigationFunction · 0.90
useLocaleFunction · 0.90
parseDateRangeFunction · 0.90
getItemFunction · 0.90
getOffsetDateRangeFunction · 0.90
getCompareDateFunction · 0.90

Tested by

no test coverage detected