( timeButton: string, datePickerValue: RangeValue | [], init?: boolean )
| 2 | import { $t } from '@common/locales' |
| 3 | |
| 4 | export function getTime( |
| 5 | timeButton: string, |
| 6 | datePickerValue: RangeValue | [], |
| 7 | init?: boolean |
| 8 | ): { startTime: number; endTime: number } { |
| 9 | const currentSecond = new Date().getTime() // 当前毫秒数时间戳 |
| 10 | let currentMin = currentSecond - (currentSecond % (60 * 1000)) // 当前分钟数时间戳 |
| 11 | let startMin = currentMin - 60 * 60 * 1000 |
| 12 | if (!init && timeButton) { |
| 13 | switch (timeButton) { |
| 14 | case 'hour': { |
| 15 | startMin = currentMin - 60 * 60 * 1000 |
| 16 | break |
| 17 | } |
| 18 | case 'day': { |
| 19 | startMin = currentMin - 24 * 60 * 60 * 1000 |
| 20 | break |
| 21 | } |
| 22 | case 'threeDays': { |
| 23 | startMin = new Date(new Date().setHours(0, 0, 0, 0)).getTime() - 2 * 24 * 60 * 60 * 1000 |
| 24 | break |
| 25 | } |
| 26 | case 'sevenDays': { |
| 27 | startMin = new Date(new Date().setHours(0, 0, 0, 0)).getTime() - 6 * 24 * 60 * 60 * 1000 |
| 28 | break |
| 29 | } |
| 30 | } |
| 31 | } else if (datePickerValue?.length === 2) { |
| 32 | startMin = datePickerValue[0]!.startOf('day').unix() |
| 33 | currentMin = datePickerValue[1]!.endOf('day').unix() |
| 34 | } |
| 35 | |
| 36 | return { startTime: startMin / 1000, endTime: currentMin / 1000 } |
| 37 | } |
| 38 | |
| 39 | export function getTimeUnit(timeInterval: string): string { |
| 40 | let timeUnit = '' |
no outgoing calls
no test coverage detected