Skip to content

Commit

Permalink
MudDatePicker: Fix GoToDate with Persian calendar (MudBlazor#8909)
Browse files Browse the repository at this point in the history
Co-authored-by: PALIZ-DEVOPS\ajr <[email protected]>
  • Loading branch information
ajahangard and PALIZ-DEVOPS\ajr authored May 8, 2024
1 parent 6dfefb3 commit 4e271a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/MudBlazor.UnitTests/Components/DatePickerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PersianDatePickerTest>();
var datePicker = comp.FindComponent<MudDatePicker>().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()
{
Expand Down
6 changes: 4 additions & 2 deletions src/MudBlazor/Components/DatePicker/MudDatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -327,7 +328,8 @@ public void GoToDate()
/// </summary>
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);
Expand Down

0 comments on commit 4e271a6

Please sign in to comment.