feat: chat list group by time range

This commit is contained in:
Timothy J. Baek
2024-05-04 01:23:02 -07:00
parent 84ec58873a
commit 53dae39042
3 changed files with 68 additions and 21 deletions
+23
View File
@@ -520,3 +520,26 @@ export const approximateToHumanReadable = (nanoseconds: number) => {
return results.reverse().join(' ');
};
export const getTimeRange = (timestamp) => {
const now = new Date();
const date = new Date(timestamp * 1000); // Convert Unix timestamp to milliseconds
// Calculate the difference in milliseconds
const diffTime = now.getTime() - date.getTime();
const diffDays = diffTime / (1000 * 3600 * 24);
if (diffDays < 1) {
return 'Today';
} else if (diffDays < 2) {
return 'Yesterday';
} else if (diffDays <= 7) {
return 'Previous 7 days';
} else if (diffDays <= 30) {
return 'Previous 30 days';
} else if (date.getFullYear() === now.getFullYear()) {
return date.toLocaleString('default', { month: 'long' });
} else {
return date.getFullYear().toString();
}
};