From f2d2522210d343cfdcce72d6b663e3bc8c02a1c8 Mon Sep 17 00:00:00 2001 From: HelenHuang <LinHuang@pollex.com.tw> Date: 星期一, 22 十一月 2021 12:31:02 +0800 Subject: [PATCH] add: 顧問-查看滿意度評分 畫面刻版 --- 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