mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 15:30:56 +00:00
60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { format } from 'date-fns';
|
|
|
|
export const formatCurrency = (amount: number, currency: string = 'ETB'): string => {
|
|
return new Intl.NumberFormat('en-US', {
|
|
style: 'currency',
|
|
currency,
|
|
currencyDisplay: 'code',
|
|
minimumFractionDigits: 2,
|
|
}).format(amount / 100).replace(/^([A-Z]{3})/, '$1 ').trim();
|
|
};
|
|
|
|
export const formatDate = (date?: string | Date | null, formatStr: string = 'MMM dd, yyyy'): string => {
|
|
if (!date) return 'N/A';
|
|
const d = new Date(date);
|
|
if (isNaN(d.getTime())) return 'N/A';
|
|
return format(d, formatStr);
|
|
};
|
|
|
|
export const formatDateTime = (date?: string | Date | null): string => {
|
|
if (!date) return 'N/A';
|
|
const d = new Date(date);
|
|
if (isNaN(d.getTime())) return 'N/A';
|
|
return format(d, 'MMM dd, yyyy h:mm a');
|
|
};
|
|
|
|
export const formatDateTimeShort = (date?: string | Date | null): string => {
|
|
if (!date) return 'N/A';
|
|
const d = new Date(date);
|
|
if (isNaN(d.getTime())) return 'N/A';
|
|
return format(d, 'dd MMM yy h:mm a');
|
|
};
|
|
|
|
export const formatDateTimeLocal = (date?: string | Date | null): string => {
|
|
if (!date) return 'N/A';
|
|
const d = new Date(date);
|
|
if (isNaN(d.getTime())) return 'N/A';
|
|
return format(d, 'MMM dd, yyyy h:mm a');
|
|
};
|
|
|
|
export const getStatusColor = (status: string): string => {
|
|
const colors: Record<string, string> = {
|
|
CONFIRMED: 'bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400',
|
|
PENDING: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900/20 dark:text-yellow-400',
|
|
CANCELLED: 'bg-red-100 text-red-800 dark:bg-red-900/20 dark:text-red-400',
|
|
BOARDED: 'bg-blue-100 text-blue-800 dark:bg-blue-900/20 dark:text-blue-400',
|
|
PAID: 'bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400',
|
|
FAILED: 'bg-red-100 text-red-800 dark:bg-red-900/20 dark:text-red-400',
|
|
REFUNDED: 'bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-300',
|
|
SCHEDULED: 'bg-blue-100 text-blue-800 dark:bg-blue-900/20 dark:text-blue-400',
|
|
DEPARTED: 'bg-purple-100 text-purple-800 dark:bg-purple-900/20 dark:text-purple-400',
|
|
ARRIVED: 'bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400',
|
|
DELAYED: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900/20 dark:text-yellow-400',
|
|
};
|
|
return colors[status] || 'bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-300';
|
|
};
|
|
|
|
export const cn = (...classes: (string | undefined | null | false)[]): string => {
|
|
return classes.filter(Boolean).join(' ');
|
|
};
|