Skip to content

fix: guard date-formatting utilities against invalid input - #1327

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
CollinsKRO:fix/guard-date-utils-invalid-input
Sep 6, 2026
Merged

fix: guard date-formatting utilities against invalid input#1327
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
CollinsKRO:fix/guard-date-utils-invalid-input

Conversation

@CollinsKRO

@CollinsKRO CollinsKRO commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds invalid-date guards to the date-formatting utilities in src/utils/dateUtils.ts to prevent RangeError: Invalid time value when unparseable strings/numbers are passed as input.

Changes

  • Added isValidDate() helper that checks whether a value produces a valid Date object
  • Added fallback parameter to formatDate, formatShortDate, formatTime, and formatRelative — all return an empty string (or a custom placeholder) when the input is invalid instead of throwing
  • Added comprehensive unit tests (src/utils/__tests__/dateUtils.test.ts) covering valid dates, invalid strings, empty strings, and custom fallbacks

Testing

  • ✅ All 21 new unit tests pass
  • ✅ ESLint passes with no warnings or errors
  • ✅ Type-check passes

Related

closes #1292

- Add isValidDate() helper to detect unparseable dates
- Add fallback parameter to formatDate, formatShortDate, formatTime, and formatRelative
- Return empty string (or custom fallback) when input is invalid instead of throwing RangeError
- Add comprehensive unit tests for all date formatting functions

Closes rinafcode#1292
@drips-wave

drips-wave Bot commented Sep 5, 2026

Copy link
Copy Markdown

@CollinsKRO Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit 8c42c4b into rinafcode:main Sep 6, 2026
6 of 7 checks passed
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.

Guard the date-formatting utilities against invalid input

2 participants