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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

FluentCalendar behaves incorrect when setting Culture #1854

Closed
vrassouli opened this issue Apr 14, 2024 · 7 comments
Closed

FluentCalendar behaves incorrect when setting Culture #1854

vrassouli opened this issue Apr 14, 2024 · 7 comments
Labels
community:contribution Issue will/can be addressed by community contribution status:in-progress Work is in progress

Comments

@vrassouli
Copy link
Contributor

馃悰 Bug Report

When setting Culture property of the FluentCalendar, it does not behave correctly. Infact, after reviewing the source code, I noticed that it uses the Culture property only for looking up the names (names of days and monthes) and not for the calulations.

馃捇 Repro or Code Sample

<FluentCalendar Culture="_culture"></FluentCalendar>
@code { private CultureInfo _culture = new CultureInfo("fa-IR"); }

馃槸 Current Behavior

The provided code, produces the following output:

image

Date of today (int this output) is 04/14/2024 in Gregorian calendar, which equals to 01/26/1403 in Persian calendar.

As you see in the image:

  1. the year is still 2024
  2. month name is in Persian, but the name '賳蹖乇' is the 4th month
  3. the calendars first day of month displays 13

馃 Expected Behavior

  1. The year should display 1403
  2. Month name should display '賮乇賵乇丿蹖賳'
  3. First day of month should be 1

馃拋 Possible Solution

The calculations should use the Calendar property of the CultureInfo.
For example the GetMonthNameAndYear method of the CalendarExtended class is implemented as following:
var result = $"{GetMonthName(Date)} {Date.Year}";
and should be changed to:
var result = $"{GetMonthName(Date)} {Culture.Calendar.GetYear(Date)}";

馃敠 Context

For multi-language applications, to support better user experience, it's vital to make use of the features provided by the CultureInfo and the Calendar

馃實 Your Environment

Windows 11, Android, iOS
Edge, Chrome, Firefox

@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Apr 14, 2024
@vrassouli
Copy link
Contributor Author

By the way, I can fix it and do a PR if required.
Thanks

@vnbaaij
Copy link
Collaborator

vnbaaij commented Apr 14, 2024

As you understand the intricacies of such a calendar much better than we can, yes please supply a PR for this!

Would be extra great is you can also add some unit tests for those cultures so we can monitor if we don't break stuff in the future (whichever culture we use).

@dvoituron
Copy link
Collaborator

@vrassouli I agree with Vincent. It would be great to offer a PR that manages this culture too.

@vrassouli
Copy link
Contributor Author

I'd be glad to
I think it would be better to have some extension methods for DateTime to handle the calculations with the CultureInfo.
If you agree, I will extend the DateTimeExtensions class with the required methods

@dvoituron
Copy link
Collaborator

Sure but to include in the component. If I correctly understand, depending of the Culture, the display values must be adapted.

Correct ?

@vrassouli
Copy link
Contributor Author

For example, there is a method named FirstDayOfMonth in FluentCalendar.razor.cs file, which returns the first day of month (and not using the culture)
This method should be replace with already-existing StartOfMonth extension method of the DateTimeExtensions, which uses CultureInfo.
As I see, StartOfMonth is implemented, but not referenced anywhere.
I've not reviewd all the methods yet, but some required ones may be already implemented and some might not.

If you agree, I want to use these extensions and implement any missing ones.

@dvoituron
Copy link
Collaborator

Yes. Sure. The best is to create or adapt the code and we will discuss in the PR with the concrete code.

We trust in you.

@vnbaaij vnbaaij added status:in-progress Work is in progress community:contribution Issue will/can be addressed by community contribution and removed triage New issue. Needs to be looked at labels Apr 14, 2024
vrassouli pushed a commit to vrassouli/fluentui-blazor that referenced this issue Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community:contribution Issue will/can be addressed by community contribution status:in-progress Work is in progress
Projects
None yet
Development

No branches or pull requests

3 participants