import { Injectable } from '@angular/core' ; import { formatDate } from '@angular/common' ; import { WeekDayIndex } from 'ngx-tethys/util' ; export function DATE_HELPER_SERVICE_FACTORY ( ) { return new DateHelperByDatePipe ( ) ; } @ Injectable ( { providedIn : 'root' , useFactory : DATE_HELPER_SERVICE_FACTORY } ) export abstract class DateHelperService { relyOnDatePipe : boolean = this instanceof DateHelperByDatePipe ; abstract getISOWeek ( date ) ; abstract getFirstDayOfWeek ( ) ; abstract format ( date , formatStr ) ; } export class DateHelperByDatePipe extends DateHelperService { getISOWeek ( date ) { return + this . format ( date , 'w' ) ; } getFirstDayOfWeek ( ) { return 0 ; } format ( date , formatStr ) { return date ? formatDate ( date , formatStr , 'zh-Hans' ) : '' ; } transCompatFormat ( format ) { return format && format . replace ( /Y/g , 'y' ) . replace ( /D/g , 'd' ) ; } }