feat: 用户会话旧在线用户

This commit is contained in:
TsMask
2023-09-26 14:34:02 +08:00
parent e77614a86c
commit 61eea0ec90
5 changed files with 464 additions and 5 deletions

View File

@@ -60,13 +60,15 @@ export function parseDatePath(date: number | Date = Date.now()): string {
* 判断两次时间差
* @param endDate 结束时间
* @param startDate 开始时间
* @returns 单位
* @param unit 单位
* @returns 单位数值
*/
export function diffSeconds(
endDate: number | Date,
startDate: number | Date
export function diffValue(
endDate: string | number | Date,
startDate: string | number | Date,
unit: 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year'
): number {
const value = Math.ceil(dayjs(endDate).diff(startDate, 'seconds'));
const value = Math.ceil(dayjs(endDate).diff(startDate, unit));
if (Number.isNaN(value)) return 0;
return value;
}