Skip to content

fix(utils): resolve Safari date parsing issue by normalizing ISO strings#874

Open
messiawrq-design wants to merge 1 commit into
ritesh-1918:mainfrom
messiawrq-design:fix/safari-date-parsing
Open

fix(utils): resolve Safari date parsing issue by normalizing ISO strings#874
messiawrq-design wants to merge 1 commit into
ritesh-1918:mainfrom
messiawrq-design:fix/safari-date-parsing

Conversation

@messiawrq-design
Copy link
Copy Markdown

@messiawrq-design messiawrq-design commented May 31, 2026

Description

This PR fixes the ticket timeline date parsing discrepancies observed on older Safari browsers, as outlined in #642.

Changes Made:

  • Updated Frontend/src/utils/dateUtils.js to normalize incoming date strings by converting space-separated formats (YYYY-MM-DD HH:MM:SS) into strict ISO-8601 strings (using a T separator) before passing them to the native Date constructor. Safari historically returns Invalid Date for timestamps missing the T separator.
  • Ensured the fix acts as a seamless pre-processor, preserving all downstream UTC normalization and timezone logic.

Related Issues

Closes #642


Payout Address (Solana): 6sF8p22Gg83NKTJ6dvya7Srv4USCniZnP47DwQwK7Mtp

Summary by CodeRabbit

  • Bug Fixes
    • Improved date string parsing to ensure consistent and reliable date display across different browsers, particularly in timeline views where date formatting is critical.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

@messiawrq-design is attempting to deploy a commit to the ritesh Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 31, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR improves the formatTimelineDate function in dateUtils.js to normalize date string parsing across browsers. The function now converts space-separated date-time strings to ISO format and intelligently handles timezone markers, appending Z only when timezone information is absent, ensuring Safari and other browsers parse Supabase timestamps correctly.

Changes

Date Parsing Compatibility

Layer / File(s) Summary
formatTimelineDate date normalization
Frontend/src/utils/dateUtils.js
The formatTimelineDate function now preprocesses string inputs by converting YYYY-MM-DD HH:MM:SS format to YYYY-MM-DDTHH:MM:SS, then conditionally appends Z for timezone-less strings while preserving existing timezone markers (Z or +) to ensure consistent parsing across Safari, Firefox, and Chrome.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • ritesh-1918/HELPDESK.AI#677: Modifies formatTimelineDate with similar ISO normalization and timezone marker handling.
  • ritesh-1918/HELPDESK.AI#803: Updates formatTimelineDate to handle Safari/timezone-less inputs by converting space-separated format to T-separated and applying timezone heuristics.
  • ritesh-1918/HELPDESK.AI#755: Normalizes nonstandard ISO inputs by converting YYYY-MM-DD HH:MM:SS space to T and defaulting missing timezone info to Z.

Suggested labels

gssoc, level:intermediate, type:bug

Poem

🐰 A rabbit once parsed dates with care,
Space to T in the parser's lair,
Safari now smiles, timezone-aware,
No more Invalid Date despair! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR addresses Safari date parsing normalization (#642) but lacks unit tests and robust fallbacks for empty/corrupt dates as required. Add unit tests for different timezone configurations and implement fallback logic to handle empty or corrupt dates gracefully.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing Safari date parsing by normalizing ISO strings in dateUtils.js.
Out of Scope Changes check ✅ Passed The changes are limited to dateUtils.js normalization as specified in #642, with no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Warning

⚠️ This pull request might be slop. It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with 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.

Inline comments:
In `@Frontend/src/utils/dateUtils.js`:
- Around line 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).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ded2e153-af4d-468f-bd38-0b61bb141b94

📥 Commits

Reviewing files that changed from the base of the PR and between da8faf2 and 0b55214.

📒 Files selected for processing (1)
  • Frontend/src/utils/dateUtils.js

Comment on lines +16 to +18
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');
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).

@ritesh-1918
Copy link
Copy Markdown
Owner

Hi @messiawrq-design! 🙌

Thank you so much for your excellent contribution: "fix(utils): resolve Safari date parsing issue by normalizing ISO strings"! We really appreciate the high-quality code and effort you have put into the platform.

Just a quick, friendly heads-up as we prepare our manual merging and verification queues—please make sure to complete all the mandatory community steps listed below.

Once those manual steps are verified, we'll get your PR officially merged into the gssoc branch (or keep it neatly cataloged if closed as integrated) and assign it the highest possible GSSoC S-Tier labels to maximize your leaderboard points!

Let's build something amazing together! 🚀🔥


🌟 Community Support & Network Steps (Take 10 Seconds!)

As we prepare our manual verification and merging queues, please make sure you have taken a moment to complete these required steps to finalize your points:

  1. Star this repository: https://github.com/ritesh-1918/HELPDESK.AI (Mandatory)
  2. 🍴 Fork this repository: https://github.com/ritesh-1918/HELPDESK.AI/fork (Mandatory)
  3. 👤 Follow @ritesh-1918 on GitHub: https://github.com/ritesh-1918 (Mandatory - manual step)
  4. 💼 Connect on LinkedIn: https://www.linkedin.com/in/ritesh1908/ (Mandatory)

Note: Having these steps completed manually is required before your PR points are officially cleared.

@ritesh-1918 ritesh-1918 added gssoc GirlScript Summer of Code gssoc:approved GSSoC Approved PR quality:exceptional Exceptional code quality level:intermediate Intermediate level difficulty type:bug Bug fix labels May 31, 2026
@ritesh-1918
Copy link
Copy Markdown
Owner

Hi @messiawrq-design! 🙌

Thank you so much for your excellent contribution: "fix(utils): resolve Safari date parsing issue by normalizing ISO strings"! We really appreciate the high-quality code and effort you have put into the platform.

Just a quick, friendly heads-up as we prepare our manual merging and verification queues—please make sure to complete all the mandatory community steps listed below.

Once those manual steps are verified, we'll get your PR officially merged into the gssoc branch (or keep it neatly cataloged if closed as integrated) and assign it the highest possible GSSoC S-Tier labels to maximize your leaderboard points!

Let's build something amazing together! 🚀🔥


🌟 Community Support & Network Steps (Take 10 Seconds!)

As we prepare our manual verification and merging queues, please make sure you have taken a moment to complete these required steps to finalize your points:

  1. Star this repository: https://github.com/ritesh-1918/HELPDESK.AI (Mandatory)
  2. 🍴 Fork this repository: https://github.com/ritesh-1918/HELPDESK.AI/fork (Mandatory)
  3. 👤 Follow @ritesh-1918 on GitHub: https://github.com/ritesh-1918 (Mandatory - manual step)
  4. 💼 Connect on LinkedIn: https://www.linkedin.com/in/ritesh1908/ (Mandatory)

Note: Having these steps completed manually is required before your PR points are officially cleared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC Approved PR gssoc GirlScript Summer of Code level:intermediate Intermediate level difficulty quality:exceptional Exceptional code quality type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BOUNTY] [level:intermediate] Fix Ticket Timeline Date Parsing Discrepancies on Older Safari Web Browsers

2 participants