Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Frontend/src/utils/dateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ export const formatTimelineDate = (dateStr) => {

// Ensure the date string is interpreted as UTC if it's an ISO string from DB
let date;
if (typeof dateStr === 'string' && !dateStr.includes('Z') && !dateStr.includes('+')) {
// If it's a raw string without TZ, assume it was intended as UTC from our backend
date = new Date(dateStr + 'Z');
if (typeof dateStr === 'string') {
// Fix for older Safari browsers where "YYYY-MM-DD HH:MM:SS" causes Invalid Date
// We replace the space with 'T' before parsing.
dateStr = dateStr.replace(/^(\d{4}-\d{2}-\d{2})\s(\d{2}:\d{2}:\d{2}(?:\.\d+)?)/, '$1T$2');

if (!dateStr.includes('Z') && !dateStr.includes('+')) {
// If it's a raw string without TZ, assume it was intended as UTC from our backend
date = new Date(dateStr + 'Z');
Comment on lines +16 to +18
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In JavaScript Date parsing (ECMAScript / MDN), are ISO-8601 strings with negative offsets like 2026-05-31T10:00:00-05:00 valid, and would appending Z to them make them invalid or change meaning?

💡 Result:

In JavaScript, ISO-8601 strings with a negative timezone offset, such as 2026-05-31T10:00:00-05:00, are valid and correctly parsed by the Date constructor and Date.parse [1][2][3]. Appending a Z to an ISO-8601 string that already includes a timezone offset is technically invalid according to the ECMAScript specification for date time strings [4]. While some lenient parsers might ignore the extra suffix, it is generally considered an invalid date format in JavaScript and will frequently result in an Invalid Date (NaN) [1][4][5]. Regarding meaning, the Z suffix explicitly denotes UTC (Coordinated Universal Time) [2][6][7]. If a string includes both a timezone offset (e.g., -05:00) and the Z suffix, the presence of conflicting timezone information renders the string ambiguous or invalid [4]. For clear and robust code, you should either use the offset to represent local time relative to UTC or use the Z suffix to represent absolute UTC time, but never both in the same string [2][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Print the relevant section with line numbers
nl -ba Frontend/src/utils/dateUtils.js | sed -n '1,120p'

Repository: ritesh-1918/HELPDESK.AI

Length of output: 110


🏁 Script executed:

#!/bin/bash
set -euo pipefail

ls -la
test -f "Frontend/src/utils/dateUtils.js" && echo "Found: Frontend/src/utils/dateUtils.js" || (echo "Missing file"; exit 1)

# Show only the relevant portion (around the reported line range)
cat -n Frontend/src/utils/dateUtils.js | sed -n '1,120p'

Repository: ritesh-1918/HELPDESK.AI

Length of output: 4129


🏁 Script executed:

node <<'NODE'
const inputs = [
  '2026-05-31T10:00:00-05:00',
  '2026-05-31T10:00:00-05:00Z',
  '2026-05-31T10:00:00+02:00',
  '2026-05-31T10:00:00+02:00Z',
  '2026-05-31 10:00:00-05:00', // not matching existing replace regex, but included for contrast
];
for (const s of inputs) {
  const d = new Date(s);
  console.log(s, '=>', d.toString(), 'time:', d.getTime());
}
NODE

Repository: ritesh-1918/HELPDESK.AI

Length of output: 509


Handle negative timezone offsets before appending Z in formatTimelineDate. [major issue]

dateStr.includes('+') misses valid ISO offsets like -05:00, so the code appends Z and produces an invalid timestamp (new Date("...-05:00Z")Invalid Date). Update timezone detection to explicitly match Z or ±HH:MM suffix.

Proposed fix
-        if (!dateStr.includes('Z') && !dateStr.includes('+')) {
+        const hasTimeZone = /(?:Z|[+-]\d{2}:\d{2})$/i.test(dateStr);
+        if (!hasTimeZone) {
             // If it's a raw string without TZ, assume it was intended as UTC from our backend
             date = new Date(dateStr + 'Z');
         } else {
             date = new Date(dateStr);
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Frontend/src/utils/dateUtils.js` around lines 16 - 18, formatTimelineDate
currently checks dateStr.includes('+') which misses negative offsets and leads
to invalid timestamps; update the detection to test for a proper timezone suffix
pattern (either 'Z' or a ±HH:MM offset) using a regex like
/(Z|[+-]\d{2}:\d{2})$/ on the trimmed dateStr before deciding to append 'Z' so
you only append 'Z' when no explicit timezone is present (locate the logic in
formatTimelineDate and replace the includes('+') check with this regex test).

} else {
date = new Date(dateStr);
}
} else {
date = new Date(dateStr);
}
Expand Down
Loading