diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 568b0ba7f..1559d7036 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -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();