From f3e662798b3b83a83c2d60dc7b4e6cf1ee4f1331 Mon Sep 17 00:00:00 2001
From: Tomas <tomasysh@gmail.com>
Date: 星期六, 05 八月 2023 16:35:00 +0800
Subject: [PATCH] Fixed: [弱掃] p8.2 Bad use of null-like value

---
 PAMapp/plugins/filters/date.filter.ts |   26 +++++++++++++++++++-------
 1 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/PAMapp/plugins/filters/date.filter.ts b/PAMapp/plugins/filters/date.filter.ts
index 7c3670c..daa1f12 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,14 +22,16 @@
 
   const isThisYear = (compareDate: Date): boolean => {
     return compareDate.getFullYear() === today.getFullYear();
-  }
+  };
+
+  const minutes = date.getMinutes() > 9 ?  date.getMinutes() : `0${date.getMinutes()}`;
 
   if (isThisYear(date)) {
     return isToday(date)
-          ? `隞予 ${date.getHours()}:${date.getMinutes()}`
-          : `${date.getMonth() + 1}���${date.getDate()}� ${date.getHours()}:${date.getMinutes()}`;
+          ? `隞予 ${date.getHours()}:${minutes}`
+          : `${date.getMonth() + 1}/${date.getDate()} ${date.getHours()}:${minutes}`;
   } else {
-    return `${date.getFullYear()}撟�${date.getMonth() + 1}���${date.getDate()}� ${date.getHours()}:${date.getMinutes()}`;
-  }
+    return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} ${date.getHours()}:${minutes}`;
+  };
 
 })

--
Gitblit v1.8.0