| | |
| | | import Vue from 'vue' |
| | | |
| | | Vue.filter('formatDate', (value: string): string => { |
| | | const date = new Date(value); |
| | | Vue.filter('formatDate', (value: string | Date | null): string => { |
| | | let date: Date; |
| | | const today = new Date(); |
| | | |
| | | if (!value) { |
| | | return '尚無紀錄'; |
| | | }; |
| | | |
| | | if (typeof value === 'string') { |
| | | date = new Date(value); |
| | | } else { |
| | | date = value; |
| | | }; |
| | | |
| | | const isToday = (compareDate: Date): boolean => { |
| | | return compareDate.getFullYear() === today.getFullYear() |
| | |
| | | |
| | | const isThisYear = (compareDate: Date): boolean => { |
| | | return compareDate.getFullYear() === today.getFullYear(); |
| | | } |
| | | |
| | | if (!value) { |
| | | return '尚無紀錄'; |
| | | } |
| | | }; |
| | | |
| | | if (isThisYear(date)) { |
| | | return isToday(date) |
| | |
| | | : `${date.getMonth() + 1}月${date.getDate()}日 ${date.getHours()}:${date.getMinutes()}`; |
| | | } else { |
| | | return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日 ${date.getHours()}:${date.getMinutes()}`; |
| | | } |
| | | }; |
| | | |
| | | }) |