fix subscribe

This commit is contained in:
jxxghp
2023-07-04 15:56:30 +08:00
parent d543f8d97f
commit d685c71a24
2 changed files with 73 additions and 5 deletions

View File

@@ -31,3 +31,29 @@ export const isToday = (date: Date) => {
/* eslint-enable */
)
}
export const calculateTimeDifference = (inputTime: string): string => {
if (!inputTime) {
return '';
}
const inputDate = new Date(inputTime);
const currentDate = new Date();
const timeDifference = currentDate.getTime() - inputDate.getTime();
const secondsDifference = Math.floor(timeDifference / 1000);
if (secondsDifference < 60) {
return `${secondsDifference}`;
} else if (secondsDifference < 3600) {
const minutes = Math.floor(secondsDifference / 60);
return `${minutes}分钟`;
} else if (secondsDifference < 86400) {
const hours = Math.floor(secondsDifference / 3600);
return `${hours}小时`;
} else {
const days = Math.floor(secondsDifference / 86400);
return `${days}`;
}
}