feat(formatting): Update differenceInDays function to return whole days or two decimal places

This commit is contained in:
web@ppanel 2025-03-14 20:51:17 +07:00
parent 85f55def2e
commit bf58f25072

View File

@ -28,6 +28,6 @@ export function formatDate(date?: Date | number, showTime: boolean = true) {
export function differenceInDays(dateLeft: Date | number, dateRight: Date | number) { export function differenceInDays(dateLeft: Date | number, dateRight: Date | number) {
const diffInMs = differenceInMilliseconds(dateLeft, dateRight); const diffInMs = differenceInMilliseconds(dateLeft, dateRight);
const diffInDays = diffInMs / (1000 * 60 * 60 * 24); const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
if (diffInDays % 1 === 0) return diffInDays; if (diffInDays >= 1) return diffInDays.toFixed(0);
return Number(diffInDays.toFixed(1)); return Number(diffInDays.toFixed(2));
} }