Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

571 B
Raw Blame
import { endOfDay, endOfHour, startOfDay, startOfHour } from 'date-fns';

export interface AnnotationRange {
  startAt: number;
  endAt: number;
}

/**
 * Returns the `date` URL parameter value that filters the website view
 * to the day (all-day annotation) or hour (timed annotation) of an annotation.
 */
export function getAnnotationDateRangeValue(date: Date, allDay: boolean) {
  const [startDate, endDate] = allDay
    ? [startOfDay(date), endOfDay(date)]
    : [startOfHour(date), endOfHour(date)];

  return `range:${startDate.getTime()}:${endDate.getTime()}`;
}