From 19ad7fd0c0af7ec7f163c87cd8002eb80931869c Mon Sep 17 00:00:00 2001 From: Wenqi <1264578441@qq.com> Date: Wed, 5 Jun 2019 19:08:29 +0800 Subject: [PATCH] fix(module:date-picker): replace DatePipe with formatDate function (#3500) close #3487 --- components/i18n/date-helper.service.ts | 22 ++++++---------------- components/i18n/nz-i18n.module.ts | 6 +----- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/components/i18n/date-helper.service.ts b/components/i18n/date-helper.service.ts index 8d4a6931b0e..6f48406c492 100644 --- a/components/i18n/date-helper.service.ts +++ b/components/i18n/date-helper.service.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ -import { DatePipe } from '@angular/common'; +import { formatDate } from '@angular/common'; import { Inject, Injectable, Injector, Optional } from '@angular/core'; import fnsFormat from 'date-fns/format'; import fnsGetISOWeek from 'date-fns/get_iso_week'; @@ -14,15 +14,9 @@ import fnsParse from 'date-fns/parse'; import { mergeDateConfig, NzDateConfig, NZ_DATE_CONFIG } from './date-config'; import { NzI18nService } from './nz-i18n.service'; -export function DATE_HELPER_SERVICE_FACTORY( - injector: Injector, - config: NzDateConfig, - datePipe: DatePipe -): DateHelperService { +export function DATE_HELPER_SERVICE_FACTORY(injector: Injector, config: NzDateConfig): DateHelperService { const i18n = injector.get(NzI18nService); - return i18n.getDateLocale() - ? new DateHelperByDateFns(i18n, config) - : new DateHelperByDatePipe(i18n, config, datePipe); + return i18n.getDateLocale() ? new DateHelperByDateFns(i18n, config) : new DateHelperByDatePipe(i18n, config); } /** @@ -32,7 +26,7 @@ export function DATE_HELPER_SERVICE_FACTORY( @Injectable({ providedIn: 'root', useFactory: DATE_HELPER_SERVICE_FACTORY, - deps: [Injector, [new Optional(), NZ_DATE_CONFIG], DatePipe] + deps: [Injector, [new Optional(), NZ_DATE_CONFIG]] }) export abstract class DateHelperService { relyOnDatePipe: boolean = this instanceof DateHelperByDatePipe; // Indicate whether this service is rely on DatePipe @@ -92,11 +86,7 @@ export class DateHelperByDateFns extends DateHelperService { * @deprecated Maybe removed in next major version due to this serious bug */ export class DateHelperByDatePipe extends DateHelperService { - constructor( - i18n: NzI18nService, - @Optional() @Inject(NZ_DATE_CONFIG) config: NzDateConfig, - private datePipe: DatePipe - ) { + constructor(i18n: NzI18nService, @Optional() @Inject(NZ_DATE_CONFIG) config: NzDateConfig) { super(i18n, config); } @@ -113,7 +103,7 @@ export class DateHelperByDatePipe extends DateHelperService { } format(date: Date, formatStr: string): string { - return date ? this.datePipe.transform(date, formatStr, undefined, this.i18n.getLocaleId())! : ''; + return date ? formatDate(date, formatStr, this.i18n.getLocaleId())! : ''; } /** diff --git a/components/i18n/nz-i18n.module.ts b/components/i18n/nz-i18n.module.ts index 443a2429cd4..7e8a3df32d3 100644 --- a/components/i18n/nz-i18n.module.ts +++ b/components/i18n/nz-i18n.module.ts @@ -6,17 +6,13 @@ * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ -import { DatePipe } from '@angular/common'; import { NgModule } from '@angular/core'; - import { LoggerModule } from 'ng-zorro-antd/core'; - import { NzI18nPipe } from './nz-i18n.pipe'; @NgModule({ imports: [LoggerModule], declarations: [NzI18nPipe], - exports: [NzI18nPipe], - providers: [DatePipe] + exports: [NzI18nPipe] }) export class NzI18nModule {}