fix: improve date handling by validating dates before formatting#1843
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens date/time handling in UI formatting and edit-form transforms by validating parsed dates before formatting/converting, preventing runtime exceptions and falling back to raw values when inputs are not parseable.
Changes:
- Add
date-fns/isValidguards to preventRangeError: Invalid time valuewhen formatting invalid dates/times. - Fall back to the raw input string when
parseISO/parseproduces an invalidDate. - Add Vitest coverage for common valid/invalid date/time formatting scenarios in the data table formatters.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| libs/ui/src/lib/data-table/data-table-formatters.tsx | Adds isValid checks before formatting/parsing to avoid throws and enable safe fallbacks. |
| libs/ui/src/lib/data-table/tests/data-table-formatters.spec.ts | Adds regression/behavior tests for date/time formatter fallbacks and formatting shapes. |
| libs/shared/ui-core-shared/src/query-utils.ts | Prevents transformEditForm from throwing on unparseable ISO strings by validating before converting. |
| libs/features/deploy/src/utils/deploy-metadata.utils.tsx | Adds isValid checks in deployment metadata date formatting to avoid formatting invalid dates. |
there were a number of cases where dates would not be in a valid format and we would throw Now we fallback to showing the raw value (e.g. in data table)
a5cd029 to
6f6891d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
there were a number of cases where dates would not be in a valid format and we would throw
Now we fallback to showing the raw value (e.g. in data table)
Resolves a number of betterstack issues