feat: add defaultDate option to parse/isValid for partial date string support#124
Merged
knowledgecode merged 4 commits intomasterfrom May 6, 2026
Merged
feat: add defaultDate option to parse/isValid for partial date string support#124knowledgecode merged 4 commits intomasterfrom
knowledgecode merged 4 commits intomasterfrom
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
defaultDateoption (ParsedComponents) toParserOptionsso 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)ParsedComponentsinterface inparser.ts; refactorPreparseResultinpreparse.tsto extend it, eliminating duplicationtoGregorianYear/getDefaultDatehelpers inisValid.tsfor shared use byparse.tsandisValid.tsdefaultDate.Ztakes precedence overoptions.timeZonewhen both are presentCommits
feat: core implementation insrc/(parser.ts, preparse.ts, isValid.ts, parse.ts)test: test coverage fordefaultDateinisValid()andparse()docs: documentdefaultDate, add inline interface blocks, clean up redundant sectionschore: bump version to 4.5.0, update dev dependenciesTest plan
npm run lintpassesnpm testpasses (2291 tests, 71 files)parse('12:30', 'HH:mm', { defaultDate: { Y: 2024, M: 3, D: 15 } })returnsFri Mar 15 2024 12:30:00isValid('02-29', 'MM-DD', { defaultDate: { Y: 2024 } })returnstrue(leap year)isValid('02-29', 'MM-DD', { defaultDate: { Y: 2023 } })returnsfalse(non-leap year)defaultDate.ZoverridestimeZoneoption