fix: use local dates for CLI date-only values#1361
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe CLI now formats date-only values from the Node.js process’s local calendar date. Archive directory prefixes and newly created change metadata use the shared formatter, with timezone-boundary regression tests and updated OpenSpec documentation. ChangesLocal CLI date semantics
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ArchiveCommand
participant formatLocalDate
participant ArchiveDirectory
participant createChange
participant ChangeMetadata
ArchiveCommand->>formatLocalDate: Format local calendar date
formatLocalDate-->>ArchiveCommand: Return YYYY-MM-DD
ArchiveCommand->>ArchiveDirectory: Create dated archive path
createChange->>formatLocalDate: Format local calendar date
formatLocalDate-->>createChange: Return YYYY-MM-DD
createChange->>ChangeMetadata: Write created field
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/utils/date.ts (1)
7-13: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider zero-padding the year to 4 digits.
While current years naturally resolve to 4 digits, explicitly zero-padding the year to 4 digits adheres strictly to the
YYYY-MM-DDspecification format and builds resilience against edge cases involving smaller year values.💡 Proposed refactor
export function formatLocalDate(date: Date = new Date()): string { - const year = date.getFullYear(); + const year = String(date.getFullYear()).padStart(4, '0'); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); return `${year}-${month}-${day}`; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/date.ts` around lines 7 - 13, Update formatLocalDate to explicitly zero-pad the computed year to four digits before constructing the YYYY-MM-DD result, while preserving the existing month and day formatting.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/utils/date.ts`:
- Around line 7-13: Update formatLocalDate to explicitly zero-pad the computed
year to four digits before constructing the YYYY-MM-DD result, while preserving
the existing month and day formatting.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 06fb29e9-b400-458c-89b1-b2dfbcca4a7c
📒 Files selected for processing (11)
openspec/changes/fix-cli-local-date-semantics/.openspec.yamlopenspec/changes/fix-cli-local-date-semantics/design.mdopenspec/changes/fix-cli-local-date-semantics/proposal.mdopenspec/changes/fix-cli-local-date-semantics/specs/change-creation/spec.mdopenspec/changes/fix-cli-local-date-semantics/specs/cli-archive/spec.mdopenspec/changes/fix-cli-local-date-semantics/tasks.mdsrc/core/archive.tssrc/utils/change-utils.tssrc/utils/date.tstest/core/archive.test.tstest/utils/change-utils.test.ts
Summary
Fix CLI-generated date-only values so they use the effective local time zone of the Node.js process instead of truncating a UTC ISO timestamp.
This affects:
createdfield in newly generated.openspec.yamlmetadataProblem
Both code paths previously generated
YYYY-MM-DDwith:toISOString()converts the current instant to UTC before the date is extracted. Around local midnight, this can produce a different calendar date from the one observed by the user running the CLI.For example:
As a result:
created: 2026-07-14on local date2026-07-152026-07-15could be named2026-07-14-<change-name>These are date-only values intended to represent the CLI process's local calendar date, not UTC timestamps.
Changes
formatLocalDate()utility.YYYY-MM-DDfrom localDateaccessors with zero-padding.createdmetadata.2026-07-14and theAsia/Shanghailocal date is2026-07-152026-01-052026-01-05expectations.Scope
This change only affects date-only values generated programmatically by the CLI.
It does not:
Date#toISOString()Validation
pnpm run buildpnpm exec vitest run test/core/archive.test.ts test/utils/change-utils.test.tsopenspec validate fix-cli-local-date-semantics --strictSummary by CodeRabbit
YYYY-MM-DDcalendar date (timezone-aware).createdusing the local calendar date, including when UTC and local dates differ.createdmetadata across UTC/local boundaries and when dates match.