File size: 776 Bytes
447ebeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import moment from "moment";

// Add this function to format the time range display
export const getTimeRangeDisplay = (isCustomDate: boolean, startTime: string, endTime: string) => {
  if (isCustomDate) {
    return `${moment(startTime).format('MMM D, h:mm A')} - ${moment(endTime).format('MMM D, h:mm A')}`;
  }
  
  const now = moment();
  const start = moment(startTime);
  const diffMinutes = now.diff(start, 'minutes');
  
  if (diffMinutes <= 15) return 'Last 15 Minutes';
  if (diffMinutes <= 60) return 'Last Hour';
  
  const diffHours = now.diff(start, 'hours');
  if (diffHours <= 4) return 'Last 4 Hours';
  if (diffHours <= 24) return 'Last 24 Hours';
  if (diffHours <= 168) return 'Last 7 Days';
  return `${start.format('MMM D')} - ${now.format('MMM D')}`;
};