diff --git a/src/BootstrapBlazor.Server/Components/Samples/Calendars.razor b/src/BootstrapBlazor.Server/Components/Samples/Calendars.razor
index c2d0fa40645..2ec2ced7c91 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/Calendars.razor
+++ b/src/BootstrapBlazor.Server/Components/Samples/Calendars.razor
@@ -6,7 +6,7 @@
@Localizer["SubTitle"]
-
+
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Calendars.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Calendars.razor.cs
index bde8d96be69..79fa16f239e 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/Calendars.razor.cs
+++ b/src/BootstrapBlazor.Server/Components/Samples/Calendars.razor.cs
@@ -77,6 +77,14 @@ private AttributeItem[] GetAttributes() =>
Type = "RenderFragment",
ValueList = " — ",
DefaultValue = " — "
+ },
+ new()
+ {
+ Name = nameof(Calendar.FirstDayOfWeek),
+ Description = Localizer["FirstDayOfWeek"],
+ Type = "DayOfWeek",
+ ValueList = " — ",
+ DefaultValue = "Sunday"
}
];
}
diff --git a/src/BootstrapBlazor.Server/Components/Samples/DateTimePickers.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/DateTimePickers.razor.cs
index 2b87c4a60b1..2213d0f260e 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/DateTimePickers.razor.cs
+++ b/src/BootstrapBlazor.Server/Components/Samples/DateTimePickers.razor.cs
@@ -221,6 +221,14 @@ private AttributeItem[] GetAttributes() =>
DefaultValue = " — "
},
new()
+ {
+ Name = nameof(DateTimePicker.FirstDayOfWeek),
+ Description = Localizer["AttrFirstDayOfWeek"],
+ Type = "DayOfWeek",
+ ValueList = " — ",
+ DefaultValue = "Sunday"
+ },
+ new()
{
Name = "ViewMode",
Description = Localizer["Att9"],
diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json
index 63fe6cc4810..3685dbb0d70 100644
--- a/src/BootstrapBlazor.Server/Locales/en-US.json
+++ b/src/BootstrapBlazor.Server/Locales/en-US.json
@@ -2572,7 +2572,8 @@
"FeatureShowHolidaysIntro": "ShowHolidays Whether to display holidays",
"OnGetDisabledDaysCallbackEvent": "Disable date callback method",
"AttrEnableDisabledDaysCache": "Whether to enable custom disabled date cache",
- "AttrDisplayDisabledDayAsEmpty": "Display disabled date as an empty string"
+ "AttrDisplayDisabledDayAsEmpty": "Display disabled date as an empty string",
+ "AttrFirstDayOfWeek": "The first day of the week"
},
"BootstrapBlazor.Server.Components.Samples.TimePickers": {
"Title": "TimePicker",
@@ -3768,7 +3769,8 @@
"Chinese": "Chinese",
"Math": "Math",
"English": "English",
- "Study": "Study"
+ "Study": "Study",
+ "FirstDayOfWeek": "The first day of the week"
},
"BootstrapBlazor.Server.Components.Samples.Cameras": {
"Title": "Camera",
diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json
index 5450fd520d7..606db14d02e 100644
--- a/src/BootstrapBlazor.Server/Locales/zh-CN.json
+++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json
@@ -2572,7 +2572,8 @@
"FeatureShowHolidaysIntro": "ShowHolidays 是否显示假日",
"OnGetDisabledDaysCallbackEvent": "获得自定义禁用日期回调方法",
"AttrEnableDisabledDaysCache": "是否启用获得自定义禁用日期缓存",
- "AttrDisplayDisabledDayAsEmpty": "显示禁用日期为空字符串"
+ "AttrDisplayDisabledDayAsEmpty": "显示禁用日期为空字符串",
+ "AttrFirstDayOfWeek": "设置每周第一天"
},
"BootstrapBlazor.Server.Components.Samples.TimePickers": {
"Title": "TimePicker 时间选择器",
@@ -3768,7 +3769,8 @@
"Chinese": "语文",
"Math": "数学",
"English": "英语",
- "Study": "自习"
+ "Study": "自习",
+ "FirstDayOfWeek": "设置每周第一天"
},
"BootstrapBlazor.Server.Components.Samples.Cameras": {
"Title": "Camera 摄像头拍照组件",
diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj
index 9e81c4b15b8..e8410287ff9 100644
--- a/src/BootstrapBlazor/BootstrapBlazor.csproj
+++ b/src/BootstrapBlazor/BootstrapBlazor.csproj
@@ -1,7 +1,7 @@
- 9.5.0-beta11
+ 9.4.11
diff --git a/src/BootstrapBlazor/Components/Calendar/Calendar.razor.cs b/src/BootstrapBlazor/Components/Calendar/Calendar.razor.cs
index c4cb7ce2291..7a8a51a365f 100644
--- a/src/BootstrapBlazor/Components/Calendar/Calendar.razor.cs
+++ b/src/BootstrapBlazor/Components/Calendar/Calendar.razor.cs
@@ -107,7 +107,7 @@ protected override void OnInitialized()
PreviousMonth = Localizer[nameof(PreviousMonth)];
NextMonth = Localizer[nameof(NextMonth)];
Today = Localizer[nameof(Today)];
- WeekLists = [.. Localizer[nameof(WeekLists)].Value.Split(',')];
+ WeekLists = GetWeekList();
PreviousWeek = Localizer[nameof(PreviousWeek)];
NextWeek = Localizer[nameof(NextWeek)];
WeekText = Localizer[nameof(WeekText)];
@@ -124,7 +124,7 @@ protected DateTime StartDate
get
{
var d = Value.AddDays(1 - Value.Day);
- d = d.AddDays(0 - (int)d.DayOfWeek);
+ d = d.AddDays((int)FirstDayOfWeek - (int)d.DayOfWeek);
return d;
}
}
@@ -197,6 +197,12 @@ protected int GetWeekCount()
[Parameter]
public bool ShowYearButtons { get; set; } = true;
+ ///
+ /// 获得/设置 星期第一天 默认
+ ///
+ [Parameter]
+ public DayOfWeek FirstDayOfWeek { get; set; } = DayOfWeek.Sunday;
+
///
/// 选中日期时回调此方法
///
@@ -297,4 +303,12 @@ private BodyTemplateContext GetBodyTemplateContext(DateTime week)
context.Values.AddRange(Enumerable.Range(0, 7).Select(i => CreateCellValue(week.AddDays(i))));
return context;
}
+ private List GetWeekList()
+ {
+ var list = Localizer[nameof(WeekLists)].Value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();
+
+ // 调整顺序
+ var firstDayIndex = (int)FirstDayOfWeek;
+ return [.. list.Skip(firstDayIndex), .. list.Take(firstDayIndex)];
+ }
}
diff --git a/src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs b/src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs
index 8ec0f992a6c..ce0de10e3f0 100644
--- a/src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs
+++ b/src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs
@@ -537,7 +537,7 @@ private List GetWeekList()
// 调整顺序
var firstDayIndex = (int)FirstDayOfWeek;
- return list.Skip(firstDayIndex).Concat(list.Take(firstDayIndex)).ToList();
+ return [.. list.Skip(firstDayIndex), .. list.Take(firstDayIndex)];
}
private async Task UpdateDisabledDaysCache(bool force)
diff --git a/test/UnitTest/Components/CalendarTest.cs b/test/UnitTest/Components/CalendarTest.cs
index abce650f4a5..7df7dd431f8 100644
--- a/test/UnitTest/Components/CalendarTest.cs
+++ b/test/UnitTest/Components/CalendarTest.cs
@@ -233,4 +233,17 @@ await cut.InvokeAsync(() =>
});
Assert.NotEqual(v, DateTime.MinValue);
}
+
+ [Fact]
+ public void FirstDayOfWeek_Ok()
+ {
+ var cut = Context.RenderComponent(pb =>
+ {
+ pb.Add(a => a.Value, new DateTime(2025, 02, 20));
+ pb.Add(a => a.FirstDayOfWeek, DayOfWeek.Monday);
+ });
+ var labels = cut.FindAll(".calendar-table thead > tr > th");
+ Assert.Equal("一", labels[0].TextContent);
+ Assert.Equal("日", labels[6].TextContent);
+ }
}