Repository navigation
fix(core): let the date prompt accept days 30 and 31 when typed - #654
Open
kuldeepsinh19 wants to merge 1 commit into
Open
kuldeepsinh19 wants to merge 1 commit into
kuldeepsinh19 wants to merge 1 commit into
Conversation
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
🦋 Changeset detectedLatest commit: b3ca2f7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
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.
What does this PR do?
When a digit is typed into an empty month or day segment,
DatePromptfills it as0<digit>and keeps the segment open for a second digit only while the first one can still be a tens digit. For months that limit is1. For days it is2, so a3is completed as03and the cursor moves on, even though 30 and 31 are valid days. The next digit then lands in the following segment.So the 30th and 31st of a month can't be typed:
@clack/prompts1.9.0)YMD202412312024/12/01, submitted as Dec 12024/12/31MDY1231202412/03/12024, "Please enter a valid date"12/31/2024DMY3112202403/11/22024, "Please enter a valid date"31/12/2024DMY3006202403/00/62024, "Please enter a valid date"30/06/2024In year-first order the result is still a valid date, so the wrong day is submitted without any error. In the other orders the leftover digits end up in the year.
The fix raises the day limit to
3, which matches the 31-day cap#validateSegmentalready applies. A3now waits for the second digit the way0–2do:30and31are accepted;32–39show the existing "There are only 31 days in any month" error, the same way13does for months;03, like the 1st and 2nd today, or as3followed by → or Enter.Verification:
packages/core/test/prompts/date.test.ts(31 inYMD, 31/12 inDMY, and the error for32). All three fail on main (8f21c2d) and pass with this change.date()from@clack/promptswith the keystrokes shown, once against the published 1.9.0 (core 1.6.0) and once against a build of this branch.pnpm types,pnpm depsandbiome checkpass, and all 190 core tests pass. In@clack/prompts,date.test.tsand 605 other tests pass. 34 tests innote.test.tsandpath.test.tsfail on my Windows machine both on main and on this branch, so they are not related to this change.I did not open an issue first because the change is one character and the tests show the bug directly. Happy to file one if you prefer.
While testing I noticed two separate date prompt issues that this PR does not touch. Tab does not clear a pending tens digit the way the arrow keys do, so with
initialValueset, typing1, Tab,2turns the month into12. Typing past four digits in the year segment when it is the last one (MDY/DMY) keeps growing it (2024then2025gives20242025). I can send those as follow-ups.Type of change
Checklist
pnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure