Fix date time rendering when print conversation on web app

This commit is contained in:
Debanjum
2025-09-01 07:09:32 -07:00
parent 0bd4bf182c
commit 3e699e5476
2 changed files with 17 additions and 2 deletions

View File

@@ -946,7 +946,7 @@ export default function AllConversations(props: SidePanelProps) {
const currentDate = new Date();
chatSessions.forEach((chatSessionMetadata) => {
chatSessions?.forEach((chatSessionMetadata) => {
const chatDate = new Date(chatSessionMetadata.updated);
const diffTime = Math.abs(currentDate.getTime() - chatDate.getTime());
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));

View File

@@ -721,7 +721,22 @@ const ChatMessage = forwardRef<HTMLDivElement, ChatMessageProps>((props, ref) =>
function formatDate(timestamp: string) {
// Format date in HH:MM, DD MMM YYYY format
let date = new Date(timestamp + "Z");
// Handle timestamps in "YYYY-MM-DD HH:MM:SS" format from backend
let date: Date;
if (timestamp.includes(" ") && !timestamp.includes("T")) {
// Convert "YYYY-MM-DD HH:MM:SS" to ISO format
date = new Date(timestamp.replace(" ", "T") + "Z");
} else if (!timestamp.endsWith("Z")) {
date = new Date(timestamp + "Z");
} else {
date = new Date(timestamp);
}
// Check if date is valid
if (isNaN(date.getTime())) {
return "Invalid Date";
}
let time_string = date
.toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit", hour12: true })
.toUpperCase();