MCPcopy Index your code
hub / github.com/simstudioai/sim / getStartDateFromTimeRange

Function getStartDateFromTimeRange

apps/sim/lib/logs/filters.ts:63–99  ·  view source on GitHub ↗
(timeRange: TimeRange, startDate?: string)

Source from the content-addressed store, hash-verified

61 * @returns Date object for the start of the range, or null for 'All time'
62 */
63export function getStartDateFromTimeRange(timeRange: TimeRange, startDate?: string): Date | null {
64 if (timeRange === 'All time') return null
65
66 if (timeRange === 'Custom range') {
67 if (startDate) {
68 const date = new Date(startDate)
69 if (!startDate.includes('T')) date.setHours(0, 0, 0, 0)
70 return date
71 }
72 return null
73 }
74
75 const now = new Date()
76
77 switch (timeRange) {
78 case 'Past 30 minutes':
79 return new Date(now.getTime() - 30 * 60 * 1000)
80 case 'Past hour':
81 return new Date(now.getTime() - 60 * 60 * 1000)
82 case 'Past 6 hours':
83 return new Date(now.getTime() - 6 * 60 * 60 * 1000)
84 case 'Past 12 hours':
85 return new Date(now.getTime() - 12 * 60 * 60 * 1000)
86 case 'Past 24 hours':
87 return new Date(now.getTime() - 24 * 60 * 60 * 1000)
88 case 'Past 3 days':
89 return new Date(now.getTime() - 3 * 24 * 60 * 60 * 1000)
90 case 'Past 7 days':
91 return new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000)
92 case 'Past 14 days':
93 return new Date(now.getTime() - 14 * 24 * 60 * 60 * 1000)
94 case 'Past 30 days':
95 return new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000)
96 default:
97 return new Date(0)
98 }
99}
100
101/**
102 * Gets the end date for a time range.

Callers 3

LogsFunction · 0.90
applyFilterParamsFunction · 0.90
AuditLogsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected