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

Change Calculation of Calendarweek for WeekPicker #3214

Merged
merged 3 commits into from
Apr 8, 2023
Merged

Change Calculation of Calendarweek for WeekPicker #3214

merged 3 commits into from
Apr 8, 2023

Conversation

sebastian-wachsmuth
Copy link
Contributor

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • Bundle size optimization
  • Performance optimization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

The WeekPicker is currently using DateHelper.GetWeekOfYear(DateTime date, DayOfWeek firstDay) for the calculation of the Week number. DateHelper is using the InvariantCulture.

FirstDayOfWeek of the InvariantCulture is Sunday
For example, for de-DE culture, the default value of FirstDayOfWeek is Monday

Additionaly CalendarWeekRule of InvariantCulture is FirstDay
For de-DE it is FirstFourDayWeek

those differences result in different Weeknumbers for both cultures.
For Example the 3rd April 2023 is Week 15 for Invariant and 14 for de-DE

To resolve this Issue we can use the CultureInfo Property of the DatePicker

var calendar = CultureInfo.Calendar;
var calendarWeekRule = CultureInfo.DateTimeFormat.CalendarWeekRule;
var week = calendar.GetWeekOfYear(date1,calendarWeekRule, Locale.FirstDayOfWeek);

Another Issue with the german Culture is the Translation for "Week" it contains an 'h' which is also a reserved letter for the time format and will be replaced with the current hour.
The fix for this is to escape the string with quotation marks

📝 Changelog

Change calculation of Week of Year for WeekPicker, changes the displayed WeekNumber in the DropDownPanel and in the SelectedValue display

Language Changelog
🇺🇸 English
🇨🇳 Chinese

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Changelog is provided or not needed

Some languages have reserved letters in their Week.
for example the german Week is Woche and the 'h'
will be replaced by the hour resulting int 'Woc12e'
or similar
@github-actions
Copy link

github-actions bot commented Apr 3, 2023

@sebastian-wachsmuth
Copy link
Contributor Author

@dotnet-policy-service agree

@ElderJames
Copy link
Member

Thanks for contribution @sebastian-wachsmuth !

@codecov
Copy link

codecov bot commented Apr 8, 2023

Codecov Report

Patch coverage: 25.00% and project coverage change: +0.06 🎉

Comparison is base (9c69ef4) 46.10% compared to head (6163bb5) 46.16%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3214      +/-   ##
==========================================
+ Coverage   46.10%   46.16%   +0.06%     
==========================================
  Files         557      557              
  Lines       26621    26625       +4     
  Branches      266      266              
==========================================
+ Hits        12273    12292      +19     
+ Misses      14308    14293      -15     
  Partials       40       40              
Impacted Files Coverage Δ
components/date-picker/internal/DatePickerBase.cs 79.46% <0.00%> (ø)
components/date-picker/RangePicker.razor.cs 65.27% <20.00%> (-0.32%) ⬇️
...nts/date-picker/internal/DatePickerDatePanel.razor 80.95% <50.00%> (+0.46%) ⬆️

... and 3 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ElderJames ElderJames merged commit 5285bf9 into ant-design-blazor:master Apr 8, 2023
@sebastian-wachsmuth sebastian-wachsmuth deleted the fix/datepicker-calendarweek branch April 8, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants