import { Pipe , PipeTransform , OnDestroy , ChangeDetectorRef , NgModule } from '@angular/core' ; import { DateFnsInputDate , DateFnsWeekIndex } from './types' ; import { Locale } from 'date-fns' ; import startOfWeek from 'date-fns/startOfWeek' ; import { Subscription } from 'rxjs' ; import { DateFnsConfigurationService , calculateLocale } from './date-fns-configuration.service' ; @ Pipe ( { name : 'dfnsStartOfWeek' , pure : false } ) export class StartOfWeekPipe 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 ( date , options ? ) { return startOfWeek ( date , calculateLocale ( options , this . config ) ) ; } } @ NgModule ( { declarations : [ StartOfWeekPipe ] , exports : [ StartOfWeekPipe ] } ) export class StartOfWeekPipeModule { }