Skip to content

Commit

Permalink
fix(module:date-picker): replace DatePipe with formatDate function
Browse files Browse the repository at this point in the history
  • Loading branch information
wenqi73 committed May 27, 2019
1 parent 6342657 commit e19e37b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
22 changes: 6 additions & 16 deletions components/i18n/date-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@
* 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';
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);
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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())! : '';
}

/**
Expand Down
6 changes: 1 addition & 5 deletions components/i18n/nz-i18n.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

0 comments on commit e19e37b

Please sign in to comment.