保誠-保戶業務員媒合平台
Tomas
2021-11-12 dcb56b639d6e7829d82a80151571eb16280ab6bb
update#129317: [date-filter] 傳入的參數可以為 string 或 Date 或 null 型別
修改1個檔案
22 ■■■■■ 已變更過的檔案
PAMapp/plugins/filters/date.filter.ts 22 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
PAMapp/plugins/filters/date.filter.ts
@@ -1,8 +1,18 @@
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()
@@ -12,11 +22,7 @@
  const isThisYear = (compareDate: Date): boolean => {
    return compareDate.getFullYear() === today.getFullYear();
  }
  if (!value) {
    return '尚無紀錄';
  }
  };
  if (isThisYear(date)) {
    return isToday(date)
@@ -24,6 +30,6 @@
          : `${date.getMonth() + 1}月${date.getDate()}日 ${date.getHours()}:${date.getMinutes()}`;
  } else {
    return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日 ${date.getHours()}:${date.getMinutes()}`;
  }
  };
})