23 lines
620 B
TypeScript
23 lines
620 B
TypeScript
export function percentageOf(part: number, total: number): number {
|
|
return total > 0 ? Math.round((part / total) * 100) : 0;
|
|
}
|
|
|
|
/** Turns red as the deadline passes, amber once it's within 3 days. */
|
|
export function deadlineTextClass(deadline: string): string {
|
|
const hoursLeft = (new Date(deadline).getTime() - Date.now()) / 3_600_000;
|
|
|
|
if (hoursLeft <= 0) {
|
|
return 'font-medium text-destructive';
|
|
}
|
|
|
|
if (hoursLeft <= 24) {
|
|
return 'text-destructive';
|
|
}
|
|
|
|
if (hoursLeft <= 72) {
|
|
return 'text-amber-600 dark:text-amber-500';
|
|
}
|
|
|
|
return 'text-muted-foreground';
|
|
}
|