import { Pipe , PipeTransform } from '@angular/core' ; import { DateService } from '../../../services/date.service' ; import { Activity } from '../models/activity' ; @ Pipe ( { name : 'activityDateDisplay' } ) export class ActivityDateDisplayPipe implements PipeTransform { constructor ( private dateService ) { } transform ( activity ) { let display = '' ; if ( activity ) { if ( activity . startDate ) { let startDate = this . dateService . convertToLocal ( activity . startDate ) ; display = this . dateService . getShortDateAndTimeDisplay ( startDate ) ; if ( activity . endDate ) { let endDate = this . dateService . convertToLocal ( activity . endDate ) ; let startTimeDisplay = this . dateService . getShortTimeDisplay ( startDate ) ; let endTimeDisplay = this . dateService . getShortTimeDisplay ( endDate ) ; let startDateDisplay = this . dateService . getShortDateDisplay ( startDate ) ; let endDateDisplay = this . dateService . getShortDateDisplay ( endDate ) ; if ( startDateDisplay == endDateDisplay ) { display = startDateDisplay + " " + startTimeDisplay + " - " + endTimeDisplay ; } else { display = display + " - " + this . dateService . getShortDateAndTimeDisplay ( endDate ) ; } } } } return display ; } }