consumer模块完成90%,前端完成supabase对接
This commit is contained in:
15
mall/services/analytics/dateRange.uts
Normal file
15
mall/services/analytics/dateRange.uts
Normal file
@@ -0,0 +1,15 @@
|
||||
export type DateRange = { startIso: string; endIso: string }
|
||||
|
||||
export function computeDateRange(period: string): DateRange {
|
||||
const now = new Date()
|
||||
const start = new Date(now.getTime())
|
||||
if (period === '7d') start.setDate(start.getDate() - 7)
|
||||
else if (period === '30d') start.setDate(start.getDate() - 30)
|
||||
else if (period === '90d') start.setDate(start.getDate() - 90)
|
||||
else if (period === '1y') start.setFullYear(start.getFullYear() - 1)
|
||||
return { startIso: start.toISOString(), endIso: now.toISOString() }
|
||||
}
|
||||
|
||||
export function toDateOnly(iso: string): string {
|
||||
return iso.length >= 10 ? iso.substring(0, 10) : iso
|
||||
}
|
||||
Reference in New Issue
Block a user