mirror of
https://github.com/documenso/documenso.git
synced 2025-11-19 11:12:06 +10:00
feat: period select for expiry
This commit is contained in:
16
packages/ui/lib/calculate-period.ts
Normal file
16
packages/ui/lib/calculate-period.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { differenceInDays, differenceInMonths, differenceInWeeks } from 'date-fns';
|
||||
|
||||
export const calculatePeriod = (expiryDate: Date) => {
|
||||
const now = new Date();
|
||||
const daysDiff = differenceInDays(expiryDate, now);
|
||||
const weeksDiff = differenceInWeeks(expiryDate, now);
|
||||
const monthsDiff = differenceInMonths(expiryDate, now);
|
||||
|
||||
if (monthsDiff > 0) {
|
||||
return { amount: monthsDiff, unit: 'months' as const };
|
||||
} else if (weeksDiff > 0) {
|
||||
return { amount: weeksDiff, unit: 'weeks' as const };
|
||||
} else {
|
||||
return { amount: daysDiff, unit: 'days' as const };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user