mirror of
https://github.com/open-webui/open-webui
synced 2024-11-06 00:32:05 +00:00
refac: getTimeRange
This commit is contained in:
parent
36d8442c92
commit
a341cfe3fd
@ -529,15 +529,23 @@ export const getTimeRange = (timestamp) => {
|
||||
const diffTime = now.getTime() - date.getTime();
|
||||
const diffDays = diffTime / (1000 * 3600 * 24);
|
||||
|
||||
if (diffDays < 1) {
|
||||
const nowDate = now.getDate();
|
||||
const nowMonth = now.getMonth();
|
||||
const nowYear = now.getFullYear();
|
||||
|
||||
const dateDate = date.getDate();
|
||||
const dateMonth = date.getMonth();
|
||||
const dateYear = date.getFullYear();
|
||||
|
||||
if (nowYear === dateYear && nowMonth === dateMonth && nowDate === dateDate) {
|
||||
return 'Today';
|
||||
} else if (diffDays < 2) {
|
||||
} else if (nowYear === dateYear && nowMonth === dateMonth && nowDate - dateDate === 1) {
|
||||
return 'Yesterday';
|
||||
} else if (diffDays <= 7) {
|
||||
return 'Previous 7 days';
|
||||
} else if (diffDays <= 30) {
|
||||
return 'Previous 30 days';
|
||||
} else if (date.getFullYear() === now.getFullYear()) {
|
||||
} else if (nowYear === dateYear) {
|
||||
return date.toLocaleString('default', { month: 'long' });
|
||||
} else {
|
||||
return date.getFullYear().toString();
|
||||
|
Loading…
Reference in New Issue
Block a user