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

fix: chinese abbreviated day name in FluentCalendar #834

Merged
merged 10 commits into from Oct 8, 2023
22 changes: 19 additions & 3 deletions src/Core/Components/DateTime/CalendarExtended.cs
Expand Up @@ -110,22 +110,23 @@ public string GetMonthNameAndYear()
/// Returns a list of days, abbreviated and complete (Mon, Monday), ...,(Sun, Sunday) in the correct culture.
/// </summary>
/// <returns></returns>
public IEnumerable<(string Abbreviated, string Name)> GetDayNames()
public IEnumerable<(char Abbreviated, string Name)> GetDayNames()
dvoituron marked this conversation as resolved.
Show resolved Hide resolved
{
int firstDayOfWeek = (int)GetFirstDayOfWeek();
var abbreviated = Culture.DateTimeFormat.AbbreviatedDayNames;
var names = Culture.DateTimeFormat.DayNames;
var dayNames = new (string Abbreviated, string Name)[7];
var dayNames = new (char Abbreviated, string Name)[7];
dvoituron marked this conversation as resolved.
Show resolved Hide resolved

for (int i = 0; i < 7; i++)
{
dayNames[i].Name = ToTitleCase(names[i]);
dayNames[i].Abbreviated = ToTitleCase(abbreviated[i]);
dayNames[i].Abbreviated = ToAbbreviatedDisplay(ToTitleCase(abbreviated[i]));
}

return Shift(dayNames, firstDayOfWeek);
}


dvoituron marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Returns True if the specified date is in the current month of the <see cref="Date"/>.
/// </summary>
Expand Down Expand Up @@ -177,4 +178,19 @@ private string ToTitleCase(string value)
{
return Culture.TextInfo.ToTitleCase(value);
}

dvoituron marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Returns the string according to different cultures
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private char ToAbbreviatedDisplay(string value)
dvoituron marked this conversation as resolved.
Show resolved Hide resolved
{
switch (Culture.Name)
{
case string x when x.StartsWith("zh-"):
return value[1];
default: return value[0];
}
}
}
2 changes: 1 addition & 1 deletion src/Core/Components/DateTime/FluentCalendar.razor
Expand Up @@ -43,7 +43,7 @@
@foreach (var weekDay in CalendarExtended.GetDayNames())
{
<div class="week-day" part="week-day" title="@weekDay.Name" abbr="@weekDay.Name">
@weekDay.Abbreviated[0]
@weekDay.Abbreviated
dvoituron marked this conversation as resolved.
Show resolved Hide resolved
</div>
}
</div>
Expand Down