Repository navigation
fix: try the remaining formats when a week format does not match in dayjs parse - #1030
mokshupadhyay wants to merge 1 commit into
Conversation
|
@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. |
|
No actionable comments were generated in the recent review. Walkthrough周序数格式未匹配时,Day.js locale 解析会继续尝试常规日期解析及后续格式。新增测试覆盖周序数格式匹配、后续日期格式匹配和全部格式均未匹配的情况。 ChangesDay.js locale 解析
Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
formatcan be an array, andlocale.parseof 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 calledparseNoMatchNotice()and returnednullstraight away. So the formats after a week format were never tried, even though they could parse the text:The week branch now moves on to the next format (
continue) instead of returning. The "no match" notice andnullresult 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 matchintests/generate.spec.tsxcoversgggg-woandYYYY-Wofollowed by a date format, a text that does match the week format, and a text that matches nothing (stillnull). It fails onmaster(receivedundefinedwhere2020-01-15is expected) and passes now.npx rc-testpasses (17 suites, 519 passed, 2 skipped), andtsc --noEmit, ESLint onsrc/generate/dayjs.tsand Prettier are clean.Summary by CodeRabbit