Files
danswer/web/src/lib/dateUtils.ts
Chris Weaver 3984350ff9 Improvements to Query History (#17)
* Add option to download query-history as a CSV

* Add user email + more complete timestamp
2024-06-25 15:07:56 -07:00

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)
);
};