Skip to content

Fix: show error for year with more than 4 digits in Time Formatter#297

Merged
spring1843 merged 3 commits into
mainfrom
invalid-year-in-time-format
May 24, 2026
Merged

Fix: show error for year with more than 4 digits in Time Formatter#297
spring1843 merged 3 commits into
mainfrom
invalid-year-in-time-format

Conversation

@spring1843
Copy link
Copy Markdown
Owner

Fixes #281

When a user typed a year with more than 4 digits (e.g. `12345-01-01`) into the Time Formatter's date input, the tool silently produced no output. The fix validates the year portion of the date string before attempting to format, and shows a clear error message.

Changes

  • `client/src/pages/tools/time-formatter.tsx`:

    • Added `yearError` state.
    • `formatTime` now checks the year segment of `inputDate`: if it has more than 4 characters (year > 9999), it sets an error message, clears the formatted results, and returns early.
    • `handleClear` and the input-change `useEffect` also clear `yearError` appropriately.
    • Added a red error banner (with `AlertCircle` icon) rendered between the input card and the results, tagged `data-testid="year-error"`.
  • `tests/e2e/tools/time-formatter.spec.ts`: New test sets the date input to `12345-01-01` via the native value setter + synthetic events (bypassing the browser's date-picker UI), then asserts the error banner is visible, contains "4 digits", and no formatted results are shown.

Copilot AI review requested due to automatic review settings May 24, 2026 04:20
@netlify
Copy link
Copy Markdown

netlify Bot commented May 24, 2026

Deploy Preview for freedevtool ready!

Name Link
🔨 Latest commit 18edb70
🔍 Latest deploy log https://app.netlify.com/projects/freedevtool/deploys/6a127ee1d62b0b0008308058
😎 Deploy Preview https://deploy-preview-297--freedevtool.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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Time Formatter behavior when a user enters a year with more than 4 digits by validating the year segment up-front and displaying a clear inline error instead of silently producing no output.

Changes:

  • Added yearError state and a year-length validation guard in formatTime to show an error and clear results when year > 9999.
  • Added an inline error banner in the Time Formatter UI (with data-testid="year-error").
  • Added an E2E test covering the invalid 5-digit year path and asserting no formatted results are shown.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
client/src/pages/tools/time-formatter.tsx Adds year validation logic and renders an inline error banner when the year exceeds 4 digits.
tests/e2e/tools/time-formatter.spec.ts Adds an E2E test ensuring a 5-digit year shows an error and clears formatted outputs.

Comment thread client/src/pages/tools/time-formatter.tsx
@spring1843 spring1843 merged commit a434ad9 into main May 24, 2026
5 checks passed
@spring1843 spring1843 deleted the invalid-year-in-time-format branch May 24, 2026 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants