Skip to content

feat: add defaultDate option to parse/isValid for partial date string support#124

Merged
knowledgecode merged 4 commits intomasterfrom
develop
May 6, 2026
Merged

feat: add defaultDate option to parse/isValid for partial date string support#124
knowledgecode merged 4 commits intomasterfrom
develop

Conversation

@knowledgecode
Copy link
Copy Markdown
Owner

@knowledgecode knowledgecode commented May 6, 2026

Summary

  • Add defaultDate option (ParsedComponents) to ParserOptions so callers can supply fallback values for date/time components missing from the format string (e.g. parse time-only strings with a known date context)
  • Introduce ParsedComponents interface in parser.ts; refactor PreparseResult in preparse.ts to extend it, eliminating duplication
  • Extract toGregorianYear / getDefaultDate helpers in isValid.ts for shared use by parse.ts and isValid.ts
  • defaultDate.Z takes precedence over options.timeZone when both are present

Commits

  • feat: core implementation in src/ (parser.ts, preparse.ts, isValid.ts, parse.ts)
  • test: test coverage for defaultDate in isValid() and parse()
  • docs: document defaultDate, add inline interface blocks, clean up redundant sections
  • chore: bump version to 4.5.0, update dev dependencies

Test plan

  • npm run lint passes
  • npm test passes (2291 tests, 71 files)
  • Verify parse('12:30', 'HH:mm', { defaultDate: { Y: 2024, M: 3, D: 15 } }) returns Fri Mar 15 2024 12:30:00
  • Verify isValid('02-29', 'MM-DD', { defaultDate: { Y: 2024 } }) returns true (leap year)
  • Verify isValid('02-29', 'MM-DD', { defaultDate: { Y: 2023 } }) returns false (non-leap year)
  • Verify defaultDate.Z overrides timeZone option

… support

Introduce ParsedComponents interface in parser.ts and refactor PreparseResult
to extend it. Add defaultDate option to ParserOptions so callers can supply
fallback values for components missing from the format string.

- toGregorianYear/getDefaultDate helpers extracted in isValid.ts for reuse
- validatePreparseResult now validates defaultDate components (e.g. H, Z)
- parse() merges parsed values with defaultDate, respecting precedence rules:
  defaultDate.Z takes precedence over options.timeZone
Cover leap-day validation, day-range validation, timezone offset precedence,
12-hour component defaults, buddhist calendar interaction, and regression
for hour24:h24 with defaultDate.H missing from format.
- parse.md: add ParserOptions interface block, document defaultDate with
  examples, move ignoreCase after hour24 to match source order
- isValid.md: add defaultDate validation section with leap-year examples
- format.md: add FormatterOptions interface block
- index.md: remove now-redundant Types/Interfaces section
- preparse.md: fix anchor link, mention defaultDate in options summary
Update @astrojs/starlight, astro, eslint, rollup, and typescript-eslint
to latest patch/minor versions.
@knowledgecode knowledgecode merged commit b505b94 into master May 6, 2026
4 checks passed
@knowledgecode knowledgecode deleted the develop branch May 6, 2026 02:21
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