Skip to content

Commit 91dfb55

Browse files
authored
🐛 (DatePicker): ensure accurate month name retrieval across locales (#2558)
1 parent f3831ff commit 91dfb55

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/Masa.Blazor/Components/DatePicker/Util/DateFormatters.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public static Func<DateOnly, string> AbbreviatedDayOfWeek(CultureInfo locale)
3131
{
3232
// try
3333
// {
34-
return date => locale.DateTimeFormat.GetAbbreviatedDayName(date.DayOfWeek);
34+
return date => locale.DateTimeFormat.GetAbbreviatedDayName(date.DayOfWeek);
3535
// }
3636
// catch (ArgumentOutOfRangeException)
3737
// {
3838
// return date => CultureInfo.InvariantCulture.DateTimeFormat.GetAbbreviatedDayName(date.DayOfWeek);
3939
// }
4040
}
41-
41+
4242
/// <summary>
4343
/// Get the shortest day of week name
4444
/// </summary>
@@ -48,7 +48,7 @@ public static Func<DateOnly, string> ShortestDayOfWeek(CultureInfo locale)
4848
{
4949
// try
5050
// {
51-
return date => locale.DateTimeFormat.GetShortestDayName(date.DayOfWeek);
51+
return date => locale.DateTimeFormat.GetShortestDayName(date.DayOfWeek);
5252
// }
5353
// catch (ArgumentOutOfRangeException)
5454
// {
@@ -86,7 +86,11 @@ public static Func<DateOnly, string> Month(CultureInfo locale)
8686
{
8787
try
8888
{
89-
return date => locale.DateTimeFormat.GetMonthName(date.Month);
89+
return date =>
90+
{
91+
int monthInCalendar = locale.DateTimeFormat.Calendar.GetMonth(date.ToDateTime(TimeOnly.MinValue));
92+
return locale.DateTimeFormat.GetMonthName(monthInCalendar);
93+
};
9094
}
9195
catch (ArgumentOutOfRangeException)
9296
{
@@ -103,7 +107,11 @@ public static Func<DateOnly, string> AbbreviatedMonth(CultureInfo locale)
103107
{
104108
try
105109
{
106-
return date => locale.DateTimeFormat.GetAbbreviatedMonthName(date.Month);
110+
return date =>
111+
{
112+
int monthInCalendar = locale.DateTimeFormat.Calendar.GetMonth(date.ToDateTime(TimeOnly.MinValue));
113+
return locale.DateTimeFormat.GetAbbreviatedMonthName(monthInCalendar);
114+
};
107115
}
108116
catch (ArgumentOutOfRangeException)
109117
{

0 commit comments

Comments
 (0)