Add input for selecting date format for date converter#266
Conversation
…erter Introduce an input format selector with options like Epoch, ISO, US, and EU formats. Enhance output by annotating each converted date with its specific pattern (e.g., YYYY-MM-DD). Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1a4d0308-8145-4f5a-b2e4-caf2f388d8ec Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: c8b2a9d6-8f9d-4c0d-a311-b545d3188183 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/46062f4a-48c0-4bc7-8f40-e3917ba2ed87/1a4d0308-8145-4f5a-b2e4-caf2f388d8ec/pUBbH8b Replit-Helium-Checkpoint-Created: true
✅ Deploy Preview for freedevtool ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR adds an input format selector to the Date Converter tool, allowing users to explicitly specify their input date format instead of relying solely on auto-detection. This improves usability when the auto-detect feature might be ambiguous (e.g., distinguishing between US and EU date formats like MM/DD/YYYY vs DD/MM/YYYY).
Key changes:
- Added a Select dropdown for choosing input format (auto-detect, Unix seconds/milliseconds, ISO 8601, US format, EU format)
- Enhanced the DateFormat interface with a
patternfield to show format patterns alongside date examples - Updated date parsing logic to support format-specific parsing in addition to auto-detection
- Improved UI layout with a responsive grid that places the date input and format selector side-by-side
| if (format === "us") { | ||
| // MM/DD/YYYY | ||
| const match = trimmed.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/); | ||
| if (!match) return null; | ||
| const [, m, d, y] = match.map(Number); | ||
| const date = new Date(y, m - 1, d); | ||
| if (date.getFullYear() !== y || date.getMonth() + 1 !== m || date.getDate() !== d) { | ||
| return null; | ||
| } | ||
| return date; | ||
| } | ||
|
|
||
| if (format === "eu") { | ||
| // DD/MM/YYYY | ||
| const match = trimmed.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/); | ||
| if (!match) return null; | ||
| const [, d, m, y] = match.map(Number); | ||
| const date = new Date(y, m - 1, d); | ||
| if (date.getFullYear() !== y || date.getMonth() + 1 !== m || date.getDate() !== d) { | ||
| return null; | ||
| } | ||
| return date; | ||
| } |
There was a problem hiding this comment.
The date validation logic is duplicated between the US and EU format parsing. Consider extracting this validation into a helper function to reduce code duplication and improve maintainability.
For example, you could create a helper function like:
const validateDateComponents = (date: Date, year: number, month: number, day: number): boolean => {
return date.getFullYear() === year &&
date.getMonth() + 1 === month &&
date.getDate() === day;
}
Then use it in both the US and EU format parsing branches.
Add a new input format option "ISO 8601 Date (YYYY-MM-DD)" to the date converter's dropdown menu and implement parsing logic for this format. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1a4d0308-8145-4f5a-b2e4-caf2f388d8ec Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: f0952440-2900-4ec5-8080-07ba155c82b0 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/46062f4a-48c0-4bc7-8f40-e3917ba2ed87/1a4d0308-8145-4f5a-b2e4-caf2f388d8ec/pUBbH8b Replit-Helium-Checkpoint-Created: true
Adds several new date formats including RFC 822, RFC 850, RFC 1123, RFC 3339 Nano, ANSIC, Unix Date, and Ruby Date to the date converter tool. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1a4d0308-8145-4f5a-b2e4-caf2f388d8ec Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 181a0c40-3290-4bdb-8705-eb436b41d355 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/46062f4a-48c0-4bc7-8f40-e3917ba2ed87/1a4d0308-8145-4f5a-b2e4-caf2f388d8ec/pUBbH8b Replit-Helium-Checkpoint-Created: true
…into date-formats
Update the date converter component to include new input formats like SQL, RFC 2822, RFC 3339, and human-readable text, along with enhanced descriptive labels for all existing and new input options. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1a4d0308-8145-4f5a-b2e4-caf2f388d8ec Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: e475e187-e46b-46e3-8d9e-4bd563c74734 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/46062f4a-48c0-4bc7-8f40-e3917ba2ed87/1a4d0308-8145-4f5a-b2e4-caf2f388d8ec/pUBbH8b Replit-Helium-Checkpoint-Created: true
Replicate and expand `parseInputDate` in `tests/lib/date-converter.test.ts` to include tests for various input formats, invalid leap dates, and new output formats, ensuring robust date parsing and formatting. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1a4d0308-8145-4f5a-b2e4-caf2f388d8ec Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 8ad0da3b-e53a-44d7-8995-9f7a0ace29fe Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/46062f4a-48c0-4bc7-8f40-e3917ba2ed87/1a4d0308-8145-4f5a-b2e4-caf2f388d8ec/pUBbH8b Replit-Helium-Checkpoint-Created: true
Implement Shamsi/Jalali input format parsing and output formatting, including conversion logic between Jalali and Gregorian calendars in the date converter component and its corresponding unit tests. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1a4d0308-8145-4f5a-b2e4-caf2f388d8ec Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 514adcbd-2a5d-4536-abd0-89ffcee49905 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/46062f4a-48c0-4bc7-8f40-e3917ba2ed87/1a4d0308-8145-4f5a-b2e4-caf2f388d8ec/pUBbH8b Replit-Helium-Checkpoint-Created: true
Replit-Restored-To: 291b611
Replit-Restored-To: 291b611
Expand `tests/lib/date-converter.test.ts` with 78 test cases covering parsing of various input formats, invalid date handling (including leap years), output formatting for all supported formats, and round-trip conversions. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 0fe4792c-c2a1-407f-8ccd-580d07d8aef7 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: baab5a17-7b33-4ead-b052-def6ec1bf84e Replit-Helium-Checkpoint-Created: true
Remove auto-detect functionality from the date converter tool, defaulting to ISO 8601 and updating related UI and logic. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 981ef8b6-5d73-4016-ab04-e2484573a90c Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 8d865600-372a-4857-acfe-0c4fcd954756 Replit-Helium-Checkpoint-Created: true
Update the date converter to default to the Unix Epoch format instead of ISO 8601, and adjust the reset functionality accordingly. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 981ef8b6-5d73-4016-ab04-e2484573a90c Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: cf62f281-af01-4944-8f7a-249661e68636 Replit-Helium-Checkpoint-Created: true
Fixes: #91 and #90