Commit 2d43f18
authored
test(calculate): add spring-forward dst edge case (JhaSourav07#1766)
## Description
Fixes JhaSourav07#680
Added a comprehensive Vitest test case in `lib/calculate.test.ts` to
document and verify timezone-aware date resolution during Daylight
Saving Time (DST) transitions.
**Changes made:**
- Utilized Vitest's `vi.useFakeTimers()` to strictly control the system
clock.
- Set the environment timezone to `America/New_York` (spring-forward:
2024-03-10) to test the 23-hour day edge case.
- Mocked the system time to early UTC on March 10th (when NY is still
experiencing March 9th local time).
- Verified that `calculateStreak` correctly parses the dates and
maintains the active streak without breaking.
- Used strictly-typed parameters (`Parameters<typeof
calculateStreak>[0]`) for the mock calendar to ensure robust type
safety.
- Cleaned up an unused `isStreakAlive` import in the test file to
resolve an ESLint warning.
## Pillar
- [ ] 🎨 Pillar 1 — New Theme Design
- [ ] 📐 Pillar 2 — Geometric SVG Improvement
- [x] 🕐 Pillar 3 — Timezone Logic Optimization
- [ ] 🛠️ Other (Bug fix, refactoring, docs)
## Visual Preview
*N/A - This PR adds core calculation tests and resolves linter warnings;
no visual UI changes were made.*
## Checklist before requesting a review:
- [x] I have read the `CONTRIBUTING.md` file.
- [x] I have tested these changes locally
(`localhost:3000/api/streak?user=YOUR_USERNAME`).
- [x] I have run `npm run format` and `npm run lint` locally and
resolved all errors (CI will fail otherwise).
- [x] My commits follow the Conventional Commits format (e.g.,
`feat(themes): ...`, `fix(calculate): ...`).
- [x] I have updated `README.md` if I added a new theme or URL
parameter.
- [x] I have started the repo.
- [x] I have made sure that i have only one commit to merge in this PR.
- [x] The SVG output matches the CommitPulse "premium quality" aesthetic
standard (no raw elements, smooth animations, correct fonts).
- [x] (Recommended) I joined the CommitPulse Discord community for
contributor discussions, mentorship, and faster PR support.1 file changed
Lines changed: 31 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
463 | 462 | | |
464 | 463 | | |
465 | 464 | | |
466 | | - | |
467 | 465 | | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
472 | 469 | | |
473 | | - | |
474 | | - | |
475 | | - | |
| 470 | + | |
| 471 | + | |
476 | 472 | | |
477 | | - | |
478 | | - | |
479 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
480 | 477 | | |
481 | | - | |
482 | | - | |
483 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
484 | 496 | | |
485 | | - | |
486 | | - | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
487 | 500 | | |
488 | 501 | | |
489 | 502 | | |
| |||
0 commit comments