Skip to content

fix: try the remaining formats when a week format does not match in dayjs parse - #1030

Open
mokshupadhyay wants to merge 1 commit into
react-component:masterfrom
mokshupadhyay:fix/dayjs-week-parse-fallback-formats
Open

mokshupadhyay wants to merge 1 commit into
react-component:masterfrom
mokshupadhyay:fix/dayjs-week-parse-fallback-formats

Conversation

@mokshupadhyay

@mokshupadhyay mokshupadhyay commented Dec 1, 2026 •

Copy link
Copy Markdown

format can be an array, and locale.parse of the Day.js generate config tries the formats in order and returns the first one that parses. For a week format (gggg-wo, YYYY-Wo) it parses the text by hand, and when no week matched it called parseNoMatchNotice() and returned null straight away. So the formats after a week format were never tried, even though they could parse the text:

dayjsGenerateConfig.locale.parse('en_US', '2020-01-15', ['gggg-wo', 'YYYY-MM-DD']);
// before: null (and a "no match" warning), expected: 2020-01-15

The week branch now moves on to the next format (continue) instead of returning. The "no match" notice and null result are still produced once at the end of the function when no format parses a non-empty text, so a text that matches nothing behaves as before.

Test: tries fallback formats when week ordinal format does not match in tests/generate.spec.tsx covers gggg-wo and YYYY-Wo followed by a date format, a text that does match the week format, and a text that matches nothing (still null). It fails on master (received undefined where 2020-01-15 is expected) and passes now. npx rc-test passes (17 suites, 519 passed, 2 skipped), and tsc --noEmit, ESLint on src/generate/dayjs.ts and Prettier are clean.

Summary by CodeRabbit

  • 问题修复
    • 周序数日期格式无法匹配时,现在会继续尝试后续日期格式,避免过早判定解析失败。
    • 周序数格式成功匹配时仍保留原解析结果;所有格式均无法匹配时仍返回空结果。

@vercel

vercel Bot commented Dec 1, 2026

Copy link
Copy Markdown

@mokshupadhyay is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

周序数格式未匹配时,Day.js locale 解析会继续尝试常规日期解析及后续格式。新增测试覆盖周序数格式匹配、后续日期格式匹配和全部格式均未匹配的情况。

Changes

Day.js locale 解析

层 / 文件 摘要
周序数解析回退
src/generate/dayjs.ts, tests/generate.spec.tsx
周序数格式未匹配时,不再立即返回 null,而是继续常规日期解析和后续格式。测试覆盖周序数格式匹配、后续日期格式匹配及所有格式均未匹配时返回 null。

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: iamkun, kerm1it

Merge Risk: Minimal · up to 47655

Array formats that start with a week format now fall through to later formats such as YYYY-MM-DD instead of failing. This is a narrow parsing fix covered by a new test, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: try the remaining formats when a week format does not match in dayjs parse”与变更内容一致。变更将周序号格式(gggg-wo 或 YYYY-Wo)不匹配时的提前返回改为继续尝试后续格式,并新增了对应的回退测试。标题描述的是主要变更,且与 src/generate/dayjs.ts 及 tests/genera…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

标题“fix: try the remaining formats when a week format does not match in dayjs parse”与变更内容一致。变更将周序号格式(gggg-wo 或 YYYY-Wo)不匹配时的提前返回改为继续尝试后续格式,并新增了对应的回退测试。标题描述的是主要变更,且与 src/generate/dayjs.ts 及 tests/generate.spec.tsx 的改动相符。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

兔子翻开日历页,
周序格式先试一回。
若未匹配,接着解析,
后续日期也来排队。
全部格式都不合,
兔子轻轻记下 null。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2f756ef5-c9cf-41b3-a28b-c13ee0208893
Commits

Reviewing files that changed from the base of the PR and between 354232c and 47655a9.

Files selected for processing: 2

  • src/generate/dayjs.ts
  • tests/generate.spec.tsx

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

This branch has not been deployed

No deployments
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