feat: first commit

This commit is contained in:
eleanor.mao
2025-03-31 22:34:22 +08:00
commit d25187c9c8
390 changed files with 57031 additions and 0 deletions

50
src/utils/time.ts Normal file
View File

@ -0,0 +1,50 @@
import dayjs from 'dayjs';
export function formatTime(time: number | string, template = 'YYYY-MM-DD'): string {
if (!time) {
return '';
}
time = Number(time);
return dayjs(time).format(template);
}
export function formatDate(time: number | string, template = 'YYYY-MM-DD'): string {
const now = dayjs();
const oneHour = now.subtract(1, 'hour').valueOf();
time = Number(time);
if (time > oneHour) {
return '刚刚';
}
const todayStart = now.startOf('date').valueOf();
if (time > todayStart) {
return '今天';
}
const yesterdayStart = now.subtract(1, 'days').startOf('date').valueOf();
if (time > yesterdayStart) {
return '昨天';
}
return dayjs(time).format(template);
}
export function activeDate(time: number | string): string {
const now = dayjs();
time = Number(time);
// const oneHour = now.subtract(1, 'hour').valueOf();
// if (time > oneHour) {
// return '刚刚活跃';
// }
// const todayStart = now.startOf('date').valueOf();
// if (time > todayStart) {
// return '今天活跃';
// }
const yesterdayStart = now.subtract(3, 'days').startOf('date').valueOf();
if (time > yesterdayStart) {
return '3日内活跃';
}
const weakStart = now.subtract(1, 'weeks').startOf('date').valueOf();
if (time > weakStart) {
return '7日内活跃';
}
return '';
}