1
0
forked from test/crm
jcrm/frontend/src/utils/dashboard.ts
Shariq Ansari 6caff5cd59 fix: added filters and translated titles
(cherry picked from commit 4b12918ba5941ca34fc4149bb43354f8344513f8)
2025-07-10 11:53:05 +00:00

29 lines
726 B
TypeScript

import { dayjs } from "frappe-ui"
export function getLastXDays(range: number = 30): string | null {
const today = new Date()
const lastXDate = new Date(today)
lastXDate.setDate(today.getDate() - range)
return `${dayjs(lastXDate).format('YYYY-MM-DD')},${dayjs(today).format(
'YYYY-MM-DD',
)}`
}
export function formatter(range: string) {
let [from, to] = range.split(',')
return `${formatRange(from)} to ${formatRange(to)}`
}
export function formatRange(date: string) {
const dateObj = new Date(date)
return dateObj.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year:
dateObj.getFullYear() === new Date().getFullYear()
? undefined
: 'numeric',
})
}