Skip to content

Guard the date-formatting utilities against invalid input #1292

Description

@RUKAYAT-CODER

Background

The helpers in `src/utils/dateUtils.ts` (`formatDate`, `formatShortDate`, `formatTime`) pass `new Date(date)` straight into `Intl.DateTimeFormat.format`, which throws `RangeError: Invalid time value` when the input is an unparseable string/number, and `formatRelative` produces nonsensical output for the same. There is also no test file for this module. Add an invalid-date guard that returns a safe fallback (e.g. an empty string or a passed-in placeholder) and add unit tests.

Files to modify (2)

  • src/utils/dateUtils.ts
  • src/utils/tests/dateUtils.test.ts

Acceptance Criteria

  • Implemented across the listed files
  • Unit/integration tests added or updated and passing
  • No regression; follows project coding standards

Activity

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

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions