Skip to content

fix(core): let the date prompt accept days 30 and 31 when typed - #654

Open
kuldeepsinh19 wants to merge 1 commit into
bombshell-dev:mainfrom
kuldeepsinh19:fix/date-day-thirty
Open

kuldeepsinh19 wants to merge 1 commit into
bombshell-dev:mainfrom
kuldeepsinh19:fix/date-day-thirty

Conversation

@kuldeepsinh19

Copy link
Copy Markdown
Contributor

What does this PR do?

When a digit is typed into an empty month or day segment, DatePrompt fills it as 0<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 is 1. For days it is 2, so a 3 is completed as 03 and 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:

format typed before (@clack/prompts 1.9.0) after
YMD 20241231 2024/12/01, submitted as Dec 1 2024/12/31
MDY 12312024 12/03/12024, "Please enter a valid date" 12/31/2024
DMY 31122024 03/11/22024, "Please enter a valid date" 31/12/2024
DMY 30062024 03/00/62024, "Please enter a valid date" 30/06/2024

In 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 #validateSegment already applies. A 3 now waits for the second digit the way 0–2 do:

  • 30 and 31 are accepted;
  • 32–39 show the existing "There are only 31 days in any month" error, the same way 13 does for months;
  • the 3rd is entered as 03, like the 1st and 2nd today, or as 3 followed by → or Enter.

Verification:

  • Three new tests in packages/core/test/prompts/date.test.ts (31 in YMD, 31/12 in DMY, and the error for 32). All three fail on main (8f21c2d) and pass with this change.
  • The table above comes from driving date() from @clack/prompts with the keystrokes shown, once against the published 1.9.0 (core 1.6.0) and once against a build of this branch.
  • Windows, Node 20.20.2 and 24.22.3: pnpm types, pnpm deps and biome check pass, and all 190 core tests pass. In @clack/prompts, date.test.ts and 605 other tests pass. 34 tests in note.test.ts and path.test.ts fail 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 initialValue set, typing 1, Tab, 2 turns the month into 12. Typing past four digits in the year segment when it is the last one (MDY/DMY) keeps growing it (2024 then 2025 gives 20242025). I can send those as follow-ups.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b3ca2f7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clack/core Patch
@clack/prompts Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 30, 2026

Copy link
Copy Markdown

commit: b3ca2f7

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.

1 participant