Fix handling of date string that are ISO formatted
This commit is contained in:
@@ -28,18 +28,18 @@ export const dateFormatter = (v: string | number | Date | undefined | null): str
|
||||
};
|
||||
|
||||
// assuming date is in format "2025-02-26 20:52:00" where no timezone is specified
|
||||
export const getTimeSince = (date: string) => {
|
||||
export const getTimeSince = (dateToCompare: string) => {
|
||||
const nowUTC = new Date().getTime();
|
||||
const past = new Date(date.replace(" ", "T") + "Z");
|
||||
if (!dateToCompare.includes("Z")) {
|
||||
dateToCompare = dateToCompare + "Z";
|
||||
}
|
||||
const past = new Date(dateToCompare);
|
||||
|
||||
const pastUTC = past.getTime();
|
||||
const diffInMs = nowUTC - pastUTC;
|
||||
|
||||
const diffInMinutes = Math.floor(diffInMs / (1000 * 60));
|
||||
|
||||
// Remove or comment out the console.log for production
|
||||
console.log("FOR now, date", new Date(nowUTC).toISOString(), new Date(pastUTC).toISOString(), "diffInMinutes", diffInMinutes);
|
||||
|
||||
if (diffInMinutes < 1) return "a couple of seconds";
|
||||
if (diffInMinutes === 1) return "1 minute";
|
||||
if (diffInMinutes < 60) return `${diffInMinutes} minutes`;
|
||||
|
Reference in New Issue
Block a user