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
2 changes: 1 addition & 1 deletion src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function useQuery() {
}

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.

}

export function formatNumber(value: number) {
Expand Down