Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.3.1-beta27</Version>
<Version>9.3.1-beta28</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private DateTime StartDate
get
{
var d = GetSafeDayDateTime(CurrentDate, 1 - CurrentDate.Day);
d = GetSafeDayDateTime(d, 0 - (int)d.DayOfWeek);
d = GetSafeDayDateTime(d, (int)FirstDayOfWeek - (int)d.DayOfWeek);
return d;
}
}
Expand Down Expand Up @@ -388,6 +388,12 @@ public bool AllowNull
[Parameter]
public bool EnableDisabledDaysCache { get; set; } = true;

/// <summary>
/// 获得/设置 星期第一天 默认 <see cref="DayOfWeek.Sunday"/>
/// </summary>
[Parameter]
public DayOfWeek FirstDayOfWeek { get; set; } = DayOfWeek.Sunday;

[Inject]
[NotNull]
private ICalendarFestivals? CalendarFestivals { get; set; }
Expand Down Expand Up @@ -494,7 +500,7 @@ protected override void OnParametersSet()
YearPeriodText ??= Localizer[nameof(YearPeriodText)];
MonthLists = [.. Localizer[nameof(MonthLists)].Value.Split(',')];
Months = [.. Localizer[nameof(Months)].Value.Split(',')];
WeekLists = [.. Localizer[nameof(WeekLists)].Value.Split(',')];
WeekLists = GetWeekList();

Today ??= Localizer[nameof(Today)];
Yesterday ??= Localizer[nameof(Yesterday)];
Expand All @@ -513,7 +519,9 @@ protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();

_render = false;
await UpdateDisabledDaysCache(true);
_render = true;
}

private bool _render = true;
Expand All @@ -523,6 +531,15 @@ protected override async Task OnParametersSetAsync()
/// </summary>
protected override bool ShouldRender() => _render;

private List<string> GetWeekList()
{
var list = Localizer[nameof(WeekLists)].Value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();

// 调整顺序
var firstDayIndex = (int)FirstDayOfWeek;
return list.Skip(firstDayIndex).Concat(list.Take(firstDayIndex)).ToList();
}

private async Task UpdateDisabledDaysCache(bool force)
{
if (OnGetDisabledDaysCallback != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
<i class="@DateTimePickerIconClassString"></i>
}
<DatePickerBody @bind-Value="SelectedValue" @ref="_pickerBody"
<DatePickerBody @bind-Value="SelectedValue" @ref="_pickerBody" FirstDayOfWeek="FirstDayOfWeek"
ShowClearButton="AllowNull" ShowSidebar="ShowSidebar" SidebarTemplate="SidebarTemplate"
DateTimeFormat="@DateTimeFormat" DateFormat="@DateFormat" TimeFormat="@TimeFormat" ShowFooter="true"
ShowLunar="ShowLunar" ShowSolarTerm="ShowSolarTerm" ShowFestivals="ShowFestivals" ShowHolidays="ShowHolidays"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public string? Format
[NotNull]
public string? TimeFormat { get; set; }

/// <summary>
/// 获得/设置 星期第一天 默认 <see cref="DayOfWeek.Sunday"/>
/// </summary>
[Parameter]
public DayOfWeek FirstDayOfWeek { get; set; } = DayOfWeek.Sunday;

/// <summary>
/// 获得/设置 组件图标 默认 fa-regular fa-calendar-days
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions test/UnitTest/Components/DateTimePickerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,20 @@ public void SidebarTemplate_Ok()
cut.Contains("test-sidebar-template");
}

[Fact]
public void FirstDayOfWeek_Ok()
{
var cut = Context.RenderComponent<DateTimePicker<DateTime>>(pb =>
{
pb.Add(a => a.FirstDayOfWeek, DayOfWeek.Monday);
pb.Add(a => a.Value, new DateTime(2025, 02, 20));
});

var labels = cut.FindAll(".date-table tbody > tr:first-child > th");
Assert.Equal("一", labels[0].TextContent);
Assert.Equal("日", labels[6].TextContent);
}

[Fact]
public void GetSafeYearDateTime_Ok()
{
Expand Down