DataTable.constants.ts50 lines · main
| 1 | import { addDays, addHours, endOfDay, startOfDay } from 'date-fns' |
| 2 | |
| 3 | import { DatePreset } from './DataTable.types' |
| 4 | |
| 5 | export const ARRAY_DELIMITER = ',' |
| 6 | export const SLIDER_DELIMITER = '-' |
| 7 | export const SPACE_DELIMITER = '_' |
| 8 | export const RANGE_DELIMITER = '-' |
| 9 | export const SORT_DELIMITER = '.' |
| 10 | |
| 11 | export const LEVELS = ['success', 'warning', 'error'] as const |
| 12 | |
| 13 | export const presets = [ |
| 14 | { |
| 15 | label: 'Today', |
| 16 | from: startOfDay(new Date()), |
| 17 | to: endOfDay(new Date()), |
| 18 | shortcut: 'd', // day |
| 19 | }, |
| 20 | { |
| 21 | label: 'Yesterday', |
| 22 | from: startOfDay(addDays(new Date(), -1)), |
| 23 | to: endOfDay(addDays(new Date(), -1)), |
| 24 | shortcut: 'y', |
| 25 | }, |
| 26 | { |
| 27 | label: 'Last hour', |
| 28 | from: addHours(new Date(), -1), |
| 29 | to: new Date(), |
| 30 | shortcut: 'h', |
| 31 | }, |
| 32 | { |
| 33 | label: 'Last 7 days', |
| 34 | from: startOfDay(addDays(new Date(), -7)), |
| 35 | to: endOfDay(new Date()), |
| 36 | shortcut: 'w', |
| 37 | }, |
| 38 | { |
| 39 | label: 'Last 14 days', |
| 40 | from: startOfDay(addDays(new Date(), -14)), |
| 41 | to: endOfDay(new Date()), |
| 42 | shortcut: 'b', // bi-weekly |
| 43 | }, |
| 44 | { |
| 45 | label: 'Last 30 days', |
| 46 | from: startOfDay(addDays(new Date(), -30)), |
| 47 | to: endOfDay(new Date()), |
| 48 | shortcut: 'm', |
| 49 | }, |
| 50 | ] satisfies DatePreset[] |