31 lines
926 B
TypeScript
31 lines
926 B
TypeScript
import { API_BASE_URL } from '@/assets/config/api';
|
|
|
|
export const formatDateShort = (dateString: string) => {
|
|
if (!dateString) return '';
|
|
const d = new Date(dateString);
|
|
if (Number.isNaN(d.getTime())) return dateString;
|
|
return d.toLocaleDateString('pt-PT');
|
|
};
|
|
|
|
export const formatDateLong = (dateString: string) => {
|
|
if (!dateString) return '';
|
|
const d = new Date(dateString);
|
|
if (Number.isNaN(d.getTime())) return dateString;
|
|
return d.toLocaleDateString('pt-PT', {
|
|
day: '2-digit',
|
|
month: 'short',
|
|
year: 'numeric',
|
|
});
|
|
};
|
|
|
|
export const formatCurrency = (value: string) =>
|
|
`${parseFloat(value || '0').toFixed(0)} EUR`;
|
|
|
|
export const getImageUrl = (path?: string) => {
|
|
if (!path) return '';
|
|
if (path.startsWith('http')) return path;
|
|
const baseUrl = API_BASE_URL.replace(/\/pt\/app$/, '');
|
|
const imagePath = path.startsWith('/') ? path : `/${path}`;
|
|
return `${baseUrl}${imagePath}`;
|
|
};
|