Skip to content

Fix: iOS/Safari date parsing RangeError - #35

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

Fix: iOS/Safari date parsing RangeError#35
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/ios-date-parsing-range-error

Conversation

@sentry

@sentry sentry Bot commented Jul 7, 2026

Copy link
Copy Markdown

This PR addresses a RangeError: Invalid time value occurring on iOS/WebKit browsers when dateTimeFormat() attempts to format date strings. The root cause was that dateTimeFormat() was passing raw dash-delimited date strings (e.g., 'YYYY-MM-DD') directly to date-fns format(). Internally, date-fns uses new Date(), which on iOS/WebKit, cannot reliably parse dash-delimited strings, leading to the error.

The fix involves wrapping the value parameter with the existing toDate() helper function within dateTimeFormat(). The toDate() function correctly converts dash-delimited strings to a Safari-compatible format (replacing dashes with slashes) before they are passed to date-fns format(). This ensures that dates are parsed correctly across all browsers, resolving the crash on iOS devices.

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 79005a2
🔍 Latest deploy log https://app.netlify.com/projects/studenthub-student/deploys/6a4d257edb32f600087daeea
😎 Deploy Preview https://deploy-preview-35--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

export function dateTimeFormat(value: string, dateFormat: string): string {
return format(value, dateFormat, { locale: i18n.language == 'en' ? enUS : ar })
return format(toDate(value) as Date, dateFormat, { locale: i18n.language == 'en' ? enUS : ar })

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 incorrectly replaces all dashes with slashes, corrupting ISO 8601 date strings. This causes new Date() to return Invalid Date, leading to a crash.
Severity: CRITICAL

Suggested Fix

Modify the toDate() function to correctly handle ISO 8601 datetime strings. Instead of globally replacing dashes with slashes, pass the ISO string directly to new Date(), as it can parse this format natively. Remove the replace(/-/g, '/') call.

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#L19

Potential issue: The `toDate()` function at `src/utils/common.ts:19` uses
`date.replace(/-/g, '/')` to format date strings. This logic incorrectly transforms full
ISO 8601 datetime strings (e.g., from `date.toISOString()`) into an invalid format like
`2024/01/15T10:30:00.000Z`. When this invalid string is passed to `new Date()`, it
returns `Invalid Date`. This value is then used by `date-fns format()`, which throws a
`RangeError: Invalid time value`, leading to an application crash. This affects multiple
components that pass ISO strings to `dateTimeFormat`, such as `date-dropdown.tsx` and
`form-datetime.tsx`.

Also affects:

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

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