From dcb56b639d6e7829d82a80151571eb16280ab6bb Mon Sep 17 00:00:00 2001
From: Tomas <tomasysh@gmail.com>
Date: 星期五, 12 十一月 2021 22:14:46 +0800
Subject: [PATCH] update#129317: [date-filter] 傳入的參數可以為 string 或 Date 或 null 型別

---
 PAMapp/plugins/filters/date.filter.ts |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/PAMapp/plugins/filters/date.filter.ts b/PAMapp/plugins/filters/date.filter.ts
index d563e18..281c148 100644
--- a/PAMapp/plugins/filters/date.filter.ts
+++ b/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()}`;
-  }
+  };
 
 })

--
Gitblit v1.8.0