import { DatePipe } from '@angular/common'; import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ standalone: true, name: 'dateFormat', }) export class DateFormatPipe implements PipeTransform { transform(value: Date | null) { if (!value) return; const today = new Date(); const yesterday = new Date(today); yesterday.setDate(yesterday.getDate() - 1); const timeFormat = new DatePipe('en-US').transform(value, 'HH:mm a'); if ( value.getFullYear() == today.getFullYear() && value.getMonth() == today.getMonth() && value.getDate() == today.getDate() ) { return `Today, ${timeFormat}`; } else if ( value.getFullYear() == yesterday.getFullYear() && value.getMonth() == yesterday.getMonth() && value.getDate() == yesterday.getDate() ) { return `Yesterday, ${timeFormat}`; } else { return new DatePipe('en-US').transform(value, 'dd/MM/yyyy, HH:mm'); } } }