Skip to content

Fix: RangeError 'Invalid time value' in Safari date parsing - #36

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/safari-date-parsing
Open

Fix: RangeError 'Invalid time value' in Safari date parsing#36
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/safari-date-parsing

Conversation

@sentry

@sentry sentry Bot commented Jul 7, 2026

Copy link
Copy Markdown

This PR addresses the RangeError: Invalid time value occurring specifically on iPhone/Mobile Safari when displaying job available_from/available_to dates.

Root Cause:
Safari's JavaScript engine cannot parse date strings containing dashes (e.g., '2024-01-01'), resulting in an Invalid Date object. The dateTimeFormat() function in src/utils/common.ts was directly passing these raw, dash-separated strings to date-fns's format() function. When format() receives an Invalid Date, it throws the observed RangeError.

Solution:

  1. Modified dateTimeFormat() to utilize the existing toDate() helper function (also in src/utils/common.ts). toDate() correctly converts dash-separated date strings to slash-separated ones (e.g., '2024/01/01'), which Safari can parse.
  2. Added a guard using date-fns's isValid() function. If, after conversion, the date is still invalid, dateTimeFormat() will now return an empty string, preventing the RangeError from being thrown and ensuring a graceful fallback.

Fixes SH-STUDENT-APP-W
Fixes TECH-2019

@linear-code

linear-code Bot commented Jul 7, 2026

Copy link
Copy Markdown

TECH-2019

@netlify

netlify Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploy Preview for studenthub-student ready!

Name Link
🔨 Latest commit ff4b792
🔍 Latest deploy log https://app.netlify.com/projects/studenthub-student/deploys/6a4d25ce4457ef00097bfb42
😎 Deploy Preview https://deploy-preview-36--studenthub-student.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread src/utils/common.ts
import { enUS, ar } from "date-fns/locale";
import i18n from "@/18n";
import { format } from "date-fns";
import { format, isValid } from "date-fns";

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Bug: The toDate() function's global dash replacement corrupts ISO 8601 timestamps, causing new Date() to fail and downstream date formatting to return an empty string.
Severity: HIGH

Suggested Fix

Modify toDate() to avoid corrupting ISO 8601 timestamps. Instead of a global replacement, consider splitting the string by 'T', replacing dashes only in the date part, and then rejoining. Alternatively, use a more robust date parsing library or method that correctly handles ISO strings without manual manipulation.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/utils/common.ts#L6

Potential issue: The `toDate()` function globally replaces all dashes with slashes. When
called with an ISO 8601 string containing a 'T' separator (e.g., from
`Date.toISOString()`), it produces an invalid date format like
"2024/01/01T09:30:00.000Z". This string cannot be parsed by `new Date()`, leading to an
`Invalid Date` object. Consequently, `dateTimeFormat()` returns an empty string, causing
UI components like date pickers in `form-datetime.tsx` and `date-dropdown.tsx` to
display blank values.

Also affects:

  • form-datetime.tsx:59
  • date-dropdown.tsx:35

Did we get this right? 👍 / 👎 to inform future reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants