Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: week range disabled rule #177

Merged
merged 5 commits into from
Nov 23, 2020

Conversation

AlanCutFlim
Copy link
Contributor

🔗 Related issue link

Resolve #27879

💡 Background and solution

When you click 2020-12-27 ~ 2020-12-31 these days to select 2021 - 1st as end week, all the weeks before are disabled.

Previously, we use weekNumber for comparison, it works well in most cases. But when you click these days e.g. 2020-12-30, it will return 202001, which is smaller than the weeks before in 2020, and result in these weeks are disabled.

// en-us

function weekNumber(date: DateType) { // 2020-12-30
  const year = generateConfig.getYear(date); // 2020
  const week = generateConfig.locale.getWeek(locale.locale, date); // 1
  return year * 100 + week; // 202001
}

const disabled = weekNumber(date) > weekNumber(endDate);

🎈 Results

Before:
image
After:
image

@vercel
Copy link

vercel bot commented Nov 21, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/react-component/picker/kw46mlfzr
✅ Preview: https://picker-git-fix-week-disabled.react-component.vercel.app

@codecov
Copy link

codecov bot commented Nov 21, 2020

Codecov Report

Merging #177 (024ae27) into master (5b98b5c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #177   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files          45       45           
  Lines        2025     2030    +5     
  Branches      590      600   +10     
=======================================
+ Hits         2017     2022    +5     
  Misses          6        6           
  Partials        2        2           
Impacted Files Coverage Δ
src/generate/dateFns.ts 100.00% <100.00%> (ø)
src/generate/dayjs.ts 100.00% <100.00%> (ø)
src/generate/moment.ts 100.00% <100.00%> (ø)
src/hooks/useRangeDisabled.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5b98b5c...024ae27. Read the comment docs.

'en_US',
generateConfig.locale.parse('en_US', '2020-12-30', [formatStr]),
),
).toEqual(1609027200000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1609027200000 这个地方可以改一下,应该表示 2020-12-27 的 value吧。这样清楚一些。

This comment was marked as spam.

@AlanCutFlim AlanCutFlim marked this pull request as draft November 22, 2020 15:53
@xrkffgg
Copy link
Member

xrkffgg commented Nov 23, 2020

@afc163 @zombieJ PTAL

@afc163 afc163 merged commit f358f6b into react-component:master Nov 23, 2020
@xrkffgg
Copy link
Member

xrkffgg commented Nov 24, 2020

@afc163 @zombieJ 有时间发布下~

@afc163
Copy link
Member

afc163 commented Nov 24, 2020

done.

@afc163
Copy link
Member

afc163 commented Nov 24, 2020

image

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.

[WeekRangePicker] Some days are disabled after selecting a start week
3 participants