From 4e271a64c335dc09d85a818811c24cfb10089160 Mon Sep 17 00:00:00 2001 From: Amir Jahangard Date: Wed, 8 May 2024 12:19:03 +0330 Subject: [PATCH] MudDatePicker: Fix GoToDate with Persian calendar (#8909) Co-authored-by: PALIZ-DEVOPS\ajr --- .../Components/DatePickerTests.cs | 16 ++++++++++++++++ .../Components/DatePicker/MudDatePicker.cs | 6 ++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/MudBlazor.UnitTests/Components/DatePickerTests.cs b/src/MudBlazor.UnitTests/Components/DatePickerTests.cs index 882b336675a8..d3a589650655 100644 --- a/src/MudBlazor.UnitTests/Components/DatePickerTests.cs +++ b/src/MudBlazor.UnitTests/Components/DatePickerTests.cs @@ -575,6 +575,22 @@ public async Task PersianCalendar() datePicker.Instance.Text.Should().Be("1399/11/26"); } + [Test] + public async Task PersianCalendarTest_GoToDate() + { + var cal = new PersianCalendar(); + var comp = Context.RenderComponent(); + var datePicker = comp.FindComponent().Instance; + await comp.InvokeAsync(() => datePicker.OpenAsync()); + datePicker.Text.Should().Be("1399/11/26"); + await comp.InvokeAsync(() => datePicker.GoToDate(new DateTime(2024, 5, 8))); + comp.WaitForAssertion(() => datePicker.Text.Should().Be("1403/02/19")); + var button = comp + .FindAll(".mud-button-root.mud-icon-button.mud-ripple.mud-ripple-icon.mud-picker-calendar-day.mud-day") + .Single(x => x.GetAttribute("style") == "--day-id: 1;"); + button.TextContent.Should().Be("1"); + } + [Test] public void SetPickerValue_CheckText() { diff --git a/src/MudBlazor/Components/DatePicker/MudDatePicker.cs b/src/MudBlazor/Components/DatePicker/MudDatePicker.cs index 27e338eff77d..d492fb42c9b4 100644 --- a/src/MudBlazor/Components/DatePicker/MudDatePicker.cs +++ b/src/MudBlazor/Components/DatePicker/MudDatePicker.cs @@ -317,7 +317,8 @@ public void GoToDate() { if (Date.HasValue) { - PickerMonth = new DateTime(Date.Value.Year, Date.Value.Month, 1); + PickerMonth = new DateTime(Culture.Calendar.GetYear(Date.Value), Culture.Calendar.GetMonth(Date.Value), + 1, Culture.Calendar); ScrollToYear(); } } @@ -327,7 +328,8 @@ public void GoToDate() /// public async Task GoToDate(DateTime date, bool submitDate = true) { - PickerMonth = new DateTime(date.Year, date.Month, 1); + PickerMonth = new DateTime(Culture.Calendar.GetYear(date), Culture.Calendar.GetMonth(date), 1, + Culture.Calendar); if (submitDate) { await SetDateAsync(date, true);