import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'relativeTime', standalone: true, }) export class RelativeTimePipe implements PipeTransform { transform(unixtime: number): string { const now = Math.floor(Date.now() / 1000); const diff = now - unixtime; if (diff < 60) { return 'Justo ahora'; } if (diff < 3600) { const minutes = Math.floor(diff / 60); return `Hace ${minutes} minuto${minutes !== 1 ? 's' : ''}`; } if (diff < 86400) { const hours = Math.floor(diff / 3600); return `Hace ${hours} hora${hours !== 1 ? 's' : ''}`; } if (diff < 604800) { const days = Math.floor(diff / 86400); return `Hace ${days} dia${days !== 1 ? 's' : ''}`; } const date = new Date(unixtime * 1000); const currentYear = new Date().getFullYear(); const options: Intl.DateTimeFormatOptions = { month: 'short', day: 'numeric', }; if (date.getFullYear() !== currentYear) { options.year = 'numeric'; } return date.toLocaleDateString('es-MX', options); } }