mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-10-10 05:05:34 +02:00
* Add option to download query-history as a CSV * Add user email + more complete timestamp
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
export function getXDaysAgo(daysAgo: number) {
|
|
const today = new Date();
|
|
const daysAgoDate = new Date(today);
|
|
daysAgoDate.setDate(today.getDate() - daysAgo);
|
|
return daysAgoDate;
|
|
}
|
|
|
|
export const timestampToDateString = (timestamp: string) => {
|
|
const date = new Date(timestamp);
|
|
const year = date.getFullYear();
|
|
const month = date.getMonth() + 1; // getMonth() is zero-based
|
|
const day = date.getDate();
|
|
|
|
const formattedDate = `${year}-${month.toString().padStart(2, "0")}-${day
|
|
.toString()
|
|
.padStart(2, "0")}`;
|
|
return formattedDate;
|
|
};
|
|
|
|
// Options for formatting the date
|
|
const dateOptions: Intl.DateTimeFormatOptions = {
|
|
year: "numeric",
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
};
|
|
|
|
// Options for formatting the time
|
|
const timeOptions: Intl.DateTimeFormatOptions = {
|
|
hour: "numeric",
|
|
minute: "2-digit",
|
|
hour12: true, // Use 12-hour format with AM/PM
|
|
};
|
|
|
|
export const timestampToReadableDate = (timestamp: string) => {
|
|
const date = new Date(timestamp);
|
|
return (
|
|
date.toLocaleDateString(undefined, dateOptions) +
|
|
", " +
|
|
date.toLocaleTimeString(undefined, timeOptions)
|
|
);
|
|
};
|