|
| 1 | +import { PoCalendarRangePreset } from '../interfaces/po-calendar-range-preset.interface'; |
| 2 | + |
| 3 | +function startOfDay(date: Date): Date { |
| 4 | + const d = new Date(date); |
| 5 | + d.setHours(0, 0, 0, 0); |
| 6 | + return d; |
| 7 | +} |
| 8 | + |
| 9 | +function endOfDay(date: Date): Date { |
| 10 | + const d = new Date(date); |
| 11 | + d.setHours(23, 59, 59, 999); |
| 12 | + return d; |
| 13 | +} |
| 14 | + |
| 15 | +export const PO_CALENDAR_DEFAULT_RANGE_PRESETS: Array<PoCalendarRangePreset> = [ |
| 16 | + { |
| 17 | + label: 'tomorrow', |
| 18 | + dateRange: (today: Date) => { |
| 19 | + const tomorrow = new Date(today); |
| 20 | + tomorrow.setDate(tomorrow.getDate() + 1); |
| 21 | + return { |
| 22 | + start: startOfDay(tomorrow), |
| 23 | + end: endOfDay(tomorrow) |
| 24 | + }; |
| 25 | + } |
| 26 | + }, |
| 27 | + { |
| 28 | + label: 'today', |
| 29 | + dateRange: (today: Date) => ({ |
| 30 | + start: startOfDay(today), |
| 31 | + end: endOfDay(today) |
| 32 | + }) |
| 33 | + }, |
| 34 | + { |
| 35 | + label: 'yesterday', |
| 36 | + dateRange: (today: Date) => { |
| 37 | + const yesterday = new Date(today); |
| 38 | + yesterday.setDate(yesterday.getDate() - 1); |
| 39 | + return { |
| 40 | + start: startOfDay(yesterday), |
| 41 | + end: endOfDay(yesterday) |
| 42 | + }; |
| 43 | + } |
| 44 | + }, |
| 45 | + { |
| 46 | + label: '7days', |
| 47 | + dateRange: (today: Date) => { |
| 48 | + const start = new Date(today); |
| 49 | + start.setDate(start.getDate() - 6); |
| 50 | + return { |
| 51 | + start: startOfDay(start), |
| 52 | + end: endOfDay(today) |
| 53 | + }; |
| 54 | + } |
| 55 | + }, |
| 56 | + { |
| 57 | + label: '14days', |
| 58 | + dateRange: (today: Date) => { |
| 59 | + const start = new Date(today); |
| 60 | + start.setDate(start.getDate() - 13); |
| 61 | + return { |
| 62 | + start: startOfDay(start), |
| 63 | + end: endOfDay(today) |
| 64 | + }; |
| 65 | + } |
| 66 | + }, |
| 67 | + { |
| 68 | + label: '30days', |
| 69 | + dateRange: (today: Date) => { |
| 70 | + const start = new Date(today); |
| 71 | + start.setDate(start.getDate() - 29); |
| 72 | + return { |
| 73 | + start: startOfDay(start), |
| 74 | + end: endOfDay(today) |
| 75 | + }; |
| 76 | + } |
| 77 | + }, |
| 78 | + { |
| 79 | + label: '3months', |
| 80 | + dateRange: (today: Date) => { |
| 81 | + const start = new Date(today); |
| 82 | + start.setMonth(start.getMonth() - 3); |
| 83 | + return { |
| 84 | + start: startOfDay(start), |
| 85 | + end: endOfDay(today) |
| 86 | + }; |
| 87 | + } |
| 88 | + }, |
| 89 | + { |
| 90 | + label: '6months', |
| 91 | + dateRange: (today: Date) => { |
| 92 | + const start = new Date(today); |
| 93 | + start.setMonth(start.getMonth() - 6); |
| 94 | + return { |
| 95 | + start: startOfDay(start), |
| 96 | + end: endOfDay(today) |
| 97 | + }; |
| 98 | + } |
| 99 | + } |
| 100 | +]; |
0 commit comments