Files
nginx-proxy-manager/frontend/src/components/Table/Formatter/DateFormatter.tsx
Jamie Curnow 3c252db46f
All checks were successful
Close stale issues and PRs / stale (push) Successful in 23s
Fixes #4844 with more defensive date parsing
2025-11-07 21:37:22 +10:00

20 lines
664 B
TypeScript

import cn from "classnames";
import { differenceInDays, isPast } from "date-fns";
import { formatDateTime, parseDate } from "src/locale";
interface Props {
value: string;
highlightPast?: boolean;
highlistNearlyExpired?: boolean;
}
export function DateFormatter({ value, highlightPast, highlistNearlyExpired }: Props) {
const d = parseDate(value);
const dateIsPast = d ? isPast(d) : false;
const days = d ? differenceInDays(d, new Date()) : 0;
const cl = cn({
"text-danger": highlightPast && dateIsPast,
"text-warning": highlistNearlyExpired && !dateIsPast && days <= 30 && days >= 0,
});
return <span className={cl}>{formatDateTime(value)}</span>;
}