Skip to content

fix(date): resolve timezone issues in DatePrompt#486

Merged
dreyfus92 merged 3 commits intobombshell-dev:mainfrom
harshaktg:fix/date-prompt-timezone-issues
Mar 14, 2026
Merged

fix(date): resolve timezone issues in DatePrompt#486
dreyfus92 merged 3 commits intobombshell-dev:mainfrom
harshaktg:fix/date-prompt-timezone-issues

Conversation

@harshaktg
Copy link
Contributor

@harshaktg harshaktg commented Mar 14, 2026

Description

Fixes timezone-related test failures in DatePrompt where dates were off by one day when running tests in timezones east of UTC (e.g., UTC+05:30).

Problem

When running tests in UTC+05:30 (IST), 5 tests in the core package and 12 tests in the prompts package were failing because:

  • Dates were being created at local midnight using new Date(year, month, day)
  • When converted to ISO strings via .toISOString(), JavaScript converts to UTC
  • This caused dates to shift backward by one day in timezones ahead of UTC

Example:

  • new Date(2025, 0, 15) creates 2025-01-15 00:00:00 in local time (UTC+05:30)
  • Converting to UTC: 2025-01-14 18:30:00 UTC
  • .toISOString().slice(0, 10) returns '2025-01-14' ❌ (expected '2025-01-15')

Solution

Updated all date operations in DatePrompt to consistently use UTC:

  • dateToSegmentValues(): Changed to use getUTCFullYear(), getUTCMonth(), getUTCDate()
  • segmentValuesToParts(): Changed to use Date.UTC() for date validation
  • segmentValuesToDate(): Changed to create dates using Date.UTC()
  • Test helpers: Updated d() helper functions in both test files to use Date.UTC()

Testing

  • ✅ All 96 core package tests pass
  • ✅ All 534 prompts package tests pass (630 total)
  • ✅ Tested in UTC+05:30 timezone where the bug was originally discovered
  • ✅ Linting, formatting, and type checking all pass

Files Changed

  • packages/core/src/prompts/date.ts
  • packages/core/test/prompts/date.test.ts
  • packages/prompts/test/date.test.ts

Before

ar stereos 102-1 treat 2e5-leatie used when invaltd date slatted

After

1 8s (transforn 426as, setup ons, collect 2 165, tests 6i5as, environment 2ns, prepare 1 315)

- Use UTC methods in dateToSegmentValues to avoid timezone shifts
- Update segmentValuesToParts to use Date.UTC for validation
- Update segmentValuesToDate to create dates in UTC
- Fix test helper functions to use Date.UTC

Fixes date values being off by one day when running tests in
timezones east of UTC (e.g., UTC+05:30). All date operations
now consistently use UTC to ensure timezone-independent behavior.
@changeset-bot
Copy link

changeset-bot bot commented Mar 14, 2026

🦋 Changeset detected

Latest commit: 3b1d83e

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

This PR includes changesets to release 2 packages
Name Type
@clack/prompts Patch
@clack/core 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

@43081j 43081j requested a review from dreyfus92 March 14, 2026 17:34
Copy link
Member

@dreyfus92 dreyfus92 left a comment

Choose a reason for hiding this comment

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

hey @harshaktg thank you for fixing this, looks good overall just left a tiny nit 😄

Co-authored-by: paul valladares <85648028+dreyfus92@users.noreply.github.com>
@harshaktg harshaktg requested a review from dreyfus92 March 14, 2026 18:13
Copy link
Member

@dreyfus92 dreyfus92 left a comment

Choose a reason for hiding this comment

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

Thanks again @harshaktg 💜

@dreyfus92 dreyfus92 merged commit 52fce8a into bombshell-dev:main Mar 14, 2026
5 checks passed
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.

2 participants