Skip to content

Commit f97afc1

Browse files
committed
fixed activity page and helper function calculation of time
1 parent de0176e commit f97afc1

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

client/src/helpers/helper_functions.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@ export const calcTime = (dateString: string | undefined): string => {
22
if (!dateString) return "unknown time";
33

44
try {
5-
const date = new Date(dateString);
5+
// 1. If the string contains 'T' but doesn't have a timezone offset,
6+
// or if we want to treat the 'Z' as local time to match the user's intent:
7+
let formattedString = dateString;
8+
if (dateString.includes("T") && dateString.endsWith("Z")) {
9+
// Remove the 'Z' so the browser interprets this as LOCAL time, not UTC
10+
formattedString = dateString.slice(0, -1);
11+
}
12+
13+
const date = new Date(formattedString);
614
if (isNaN(date.getTime())) throw new Error("Invalid date");
715

816
const now = new Date();
17+
18+
// 2. Standardize both to ignore milliseconds for cleaner math
919
const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);
1020

11-
// 1. Check if the date is in the FUTURE
1221
const isFuture = diffInSeconds < 0;
13-
const absDiff = Math.abs(diffInSeconds); // Use Absolute Value to remove the '-'
22+
const absDiff = Math.abs(diffInSeconds);
1423

15-
// 2. Helper to format the string
1624
const formatLabel = (value: number, unit: string) => {
1725
return isFuture ? `in ${value} ${unit}` : `${value} ${unit} ago`;
1826
};
1927

20-
// 3. Logic for relative time using the absolute difference
21-
if (absDiff < 60) return formatLabel(absDiff, "seconds");
28+
// 3. Logic (Same as before)
29+
if (absDiff < 60) return isFuture ? "due now" : "just now";
2230

2331
const diffInMinutes = Math.floor(absDiff / 60);
2432
if (diffInMinutes < 60) return formatLabel(diffInMinutes, "minutes");
@@ -29,7 +37,7 @@ export const calcTime = (dateString: string | undefined): string => {
2937
const diffInDays = Math.floor(diffInHours / 24);
3038
return formatLabel(diffInDays, "days");
3139
} catch (error) {
32-
return "invalid date: " + error;
40+
return "invalid date" + error;
3341
}
3442
};
3543

client/src/pages/organization_activity.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const Organization_Activity_Page = () => {
2626
error: allError,
2727
refresh: allRefresh,
2828
}: organization_clean_backend_calls_return_interface = useOrganizationBackendGetItems(
29-
"all",
29+
"",
30+
"",
3031
);
3132

3233
console.log("Data from useOrganizationBackendGetItems:", allData);
@@ -41,7 +42,8 @@ const Organization_Activity_Page = () => {
4142
error: expiringError,
4243
refresh: expiringRefresh,
4344
}: organization_clean_backend_calls_return_interface = useOrganizationBackendGetItems(
44-
"Expiring",
45+
"",
46+
"expiryDate",
4547
);
4648

4749
console.log("Data from useOrganizationBackendGetItems:", expiringData);
@@ -55,7 +57,8 @@ const Organization_Activity_Page = () => {
5557
error: dueError,
5658
refresh: dueRefresh,
5759
}: organization_clean_backend_calls_return_interface = useOrganizationBackendGetItems(
58-
"Due",
60+
"",
61+
"dueOn",
5962
);
6063

6164
console.log("Data from useOrganizationBackendGetItems:", dueData);
@@ -69,7 +72,8 @@ const Organization_Activity_Page = () => {
6972
error: borrowedError,
7073
refresh: borrowedRefresh,
7174
}: organization_clean_backend_calls_return_interface = useOrganizationBackendGetItems(
72-
"Borrowed",
75+
"",
76+
"borrowedOn",
7377
);
7478

7579
console.log("Data from useOrganizationBackendGetItems:", borrowedData);
@@ -83,7 +87,8 @@ const Organization_Activity_Page = () => {
8387
error: returnedError,
8488
refresh: returnedRefresh,
8589
}: organization_clean_backend_calls_return_interface = useOrganizationBackendGetItems(
86-
"Returned",
90+
"",
91+
"returnedOn",
8792
);
8893

8994
console.log("Data from useOrganizationBackendGetItems:", returnedData);

0 commit comments

Comments
 (0)