Simple Managment webapp [LLM]
This commit is contained in:
21
webapp/src/app/shared/pipes/relative-time.pipe.ts
Normal file
21
webapp/src/app/shared/pipes/relative-time.pipe.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { formatDistanceToNow, parseISO } from 'date-fns';
|
||||
|
||||
@Pipe({
|
||||
name: 'relativeTime',
|
||||
standalone: true
|
||||
})
|
||||
export class RelativeTimePipe implements PipeTransform {
|
||||
transform(value: string | Date | null | undefined): string {
|
||||
if (!value) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
try {
|
||||
const date = typeof value === 'string' ? parseISO(value) : value;
|
||||
return formatDistanceToNow(date, { addSuffix: true });
|
||||
} catch {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user