From 27d109b5792305d849f578627f98e1cb55a330f4 Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期五, 11 三月 2022 15:12:54 +0800 Subject: [PATCH] Merge branch 'Phase3' into pollex-dev --- PAMapp/plugins/filters/date.filter.ts | 28 ++++++++++++++++++---------- 1 files changed, 18 insertions(+), 10 deletions(-) diff --git a/PAMapp/plugins/filters/date.filter.ts b/PAMapp/plugins/filters/date.filter.ts index d563e18..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,18 +22,16 @@ const isThisYear = (compareDate: Date): boolean => { return compareDate.getFullYear() === today.getFullYear(); - } + }; - if (!value) { - return '撠蝝����'; - } + 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