import * as moment from 'moment' ; import { Pipe , PipeTransform } from '@angular/core' ; import { DateSettingsService } from '../../settings/services/date-settings.service' ; @ Pipe ( { name : 'dateFormatter' } ) export class DateFormatterPipe implements PipeTransform { constructor ( private dateSettingsService ) { } /**
     * Converts input date string representation of the date according to the selected pattern
     */ transform ( data ) { if ( data && data . $date ) { data = new Date ( data . $date ) . toUTCString ( ) ; } if ( isNaN ( data ) && ! isNaN ( Date . parse ( data ) ) ) { const { timezone , date_format } = this . dateSettingsService . currentDateSettings ; const date = moment . utc ( data ) ; return date . isValid ( ) ? moment . tz ( date , timezone ) . format ( date_format ) : data ; } return data ; } }