Files
Investidor-V2/resources/js/lib/opportunity-information.ts
T

42 lines
1.4 KiB
TypeScript

export function opportunityDescription(record: {
title: string;
summary?: string | null;
}): string {
const summary = record.summary
?.replace(/<[^>]*>/g, ' ')
.replace(/\s+/g, ' ')
.trim();
const text =
summary || `Consulte a ficha de ${record.title} no InvesteMoz.`;
return Array.from(
text
.replace(/<[^>]*>/g, ' ')
.replace(/\s+/g, ' ')
.trim(),
)
.slice(0, 160)
.join('');
}
export function recordedVerificationDate(value?: string | null): string {
if (!value?.trim()) return 'Não registada';
const parts = /^(\d{4})-(\d{2})-(\d{2})/.exec(value);
if (!parts) return 'Data não interpretável';
const [, year, month, day] = parts.map(Number);
const calendar = new Date(Date.UTC(year, month - 1, day));
if (
calendar.getUTCFullYear() !== year ||
calendar.getUTCMonth() !== month - 1 ||
calendar.getUTCDate() !== day
)
return 'Data não interpretável';
if (value.length > 10 && !/(Z|[+-]\d{2}:\d{2})$/.test(value))
return 'Fuso horário não registado';
const date = new Date(value);
if (Number.isNaN(date.getTime())) return 'Data não interpretável';
return new Intl.DateTimeFormat('pt-MZ', {
dateStyle: 'medium',
timeZone: 'Africa/Maputo',
}).format(date);
}