From 1b57ac5bea14a750b5ddf961c3a8510da18f3637 Mon Sep 17 00:00:00 2001 From: 劉鈞霖 <benson@gmail.com> Date: 星期二, 23 十一月 2021 12:07:02 +0800 Subject: [PATCH] [ Update ] 串接顧問登入 完成 50% (驗證碼以及忘記密碼 尚未 ) 、 新增 api 錯誤訊息 。 --- 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..9a15a4e 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() > 10 ? 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