From a05bc0230218e2c3216efe5de2e9526ec1c8f251 Mon Sep 17 00:00:00 2001 From: Wenqi <1264578441@qq.com> Date: Mon, 14 Oct 2019 19:33:49 +0800 Subject: [PATCH] fix(module:time-picker): add null input judgement when using datefns (#4283) close #3854 --- components/i18n/date-helper.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/i18n/date-helper.service.ts b/components/i18n/date-helper.service.ts index bd3de010e93..f9e2d8cf004 100644 --- a/components/i18n/date-helper.service.ts +++ b/components/i18n/date-helper.service.ts @@ -75,8 +75,8 @@ export class DateHelperByDateFns extends DateHelperService { * @param date Date * @param formatStr format string */ - format(date: Date, formatStr: string): string { - return fnsFormat(date, formatStr, { locale: this.i18n.getDateLocale() }); + format(date: Date | null, formatStr: string): string { + return date ? fnsFormat(date, formatStr, { locale: this.i18n.getDateLocale() }) : ''; } } @@ -103,7 +103,7 @@ export class DateHelperByDatePipe extends DateHelperService { return this.config.firstDayOfWeek; } - format(date: Date, formatStr: string): string { + format(date: Date | null, formatStr: string): string { return date ? formatDate(date, formatStr, this.i18n.getLocaleId())! : ''; }