import { Pipe , PipeTransform , ChangeDetectorRef , OnDestroy , NgModule } from '@angular/core' ; import { DateFnsConfigurationService , calculateLocale } from './date-fns-configuration.service' ; import { Subscription } from 'rxjs' ; import { DateFnsInputDate } from './types' ; import { Locale } from 'date-fns' ; import parse from 'date-fns/parse' ; @ Pipe ( { name : 'dfnsParse' , pure : false } ) export class ParsePipe implements PipeTransform , OnDestroy { private localeChanged$ : Subscription ; constructor ( public config , public cd ) { this . localeChanged$ = this . config . localeChanged . subscribe ( _ => this . cd . markForCheck ( ) ) ; } ngOnDestroy ( ) { this . localeChanged$ . unsubscribe ( ) ; } transform ( dateString , formatString , backupDate , options ? ) { return parse ( dateString , formatString , backupDate , calculateLocale ( options , this . config ) ) ; } } @ NgModule ( { declarations : [ ParsePipe ] , exports : [ ParsePipe ] } ) export class ParsePipeModule { }