保誠-保戶業務員媒合平台
wayne
2021-11-12 505f666d3ecf3688778c079a8bbfb366d695cf22
PAMapp/plugins/filters/date.filter.ts
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,29 @@
import Vue from 'vue'
Vue.filter('formatDate', (value: string): string => {
  const date = new Date(value);
  const today = new Date();
  const isToday = (compareDate: Date): boolean => {
    return compareDate.getFullYear() === today.getFullYear()
          && compareDate.getMonth() === today.getMonth()
          && compareDate.getDate() === today.getDate();
  };
  const isThisYear = (compareDate: Date): boolean => {
    return compareDate.getFullYear() === today.getFullYear();
  }
  if (!value) {
    return '尚無紀錄';
  }
  if (isThisYear(date)) {
    return isToday(date)
          ? `今天 ${date.getHours()}:${date.getMinutes()}`
          : `${date.getMonth() + 1}月${date.getDate()}日 ${date.getHours()}:${date.getMinutes()}`;
  } else {
    return `${date.getFullYear()}å¹´${date.getMonth() + 1}月${date.getDate()}日 ${date.getHours()}:${date.getMinutes()}`;
  }
})