mirror of
https://github.com/dotnetcore/BootstrapBlazor.git
synced 2025-12-20 02:16:40 +08:00
feat(DateTimePicker): add ShowHolidays parameter (#3075)
* feat: 增加 ICalendarHolidays 接口服务 * refactor: 增加 ShowHolidays 参数 * refactor: 增加 ShowHolidays 参数 * doc: 更新假日示例 * feat: 增加 Holiday 组件包 * test: 增加组件包单元测试 * chore: 增加假日服务 * refactor: 更新样式 * chore: bump version 8.3.4-beta06 * test: 更新单元测试 * test: 更新单元测试
This commit is contained in:
@@ -139,7 +139,7 @@
|
||||
</DemoBlock>
|
||||
|
||||
<DemoBlock Title="@Localizer["ShowLunarTitle"]" Introduction="@Localizer["ShowLunarIntro"]" Name="ShowLunar">
|
||||
<DateTimePicker TValue="DateTimeOffset" ShowLunar="true" ShowSolarTerm="true" ShowFestivals="true"></DateTimePicker>
|
||||
<DateTimePicker TValue="DateTimeOffset" ShowLunar="true" ShowSolarTerm="true" ShowFestivals="true" ShowHolidays="true"></DateTimePicker>
|
||||
</DemoBlock>
|
||||
|
||||
<DemoBlock Title="@Localizer["DayTemplateTitle"]" Introduction="@Localizer["DayTemplateIntro"]" Name="DayTemplate">
|
||||
|
||||
@@ -32,6 +32,9 @@ builder.Services.Configure<HubOptions>(option => option.MaximumReceiveMessageSiz
|
||||
// 增加 BootstrapBlazor 服务
|
||||
builder.Services.AddBootstrapBlazorServices();
|
||||
|
||||
// 增加 BootstrapBlazor 假日服务
|
||||
builder.Services.AddBootstrapHolidayService();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// 启用本地化
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>8.3.4-beta05</Version>
|
||||
<Version>8.3.4-beta06</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
else
|
||||
{
|
||||
<DatePickerCell Value="@GetSafeDayDateTime(week, index)" Text="@text" OnClick="d => OnClickDateTime(d)" Template="DayTemplate!"
|
||||
ShowLunar="ShowLunar" ShowSolarTerm="ShowSolarTerm" ShowFestivals="ShowFestivals">
|
||||
ShowLunar="ShowLunar" ShowSolarTerm="ShowSolarTerm" ShowFestivals="ShowFestivals" ShowHolidays="ShowHolidays">
|
||||
</DatePickerCell>
|
||||
}
|
||||
</td>
|
||||
|
||||
@@ -362,6 +362,12 @@ public partial class DatePickerBody
|
||||
[Parameter]
|
||||
public bool ShowFestivals { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否显示休假日 默认 false
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool ShowHolidays { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否为 Range 内使用 默认为 false
|
||||
/// </summary>
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
}
|
||||
|
||||
.picker-panel-icon-btn {
|
||||
color: #303133;
|
||||
color: var(--bs-body-color);
|
||||
border: 0;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
@@ -107,6 +107,39 @@
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
cursor: pointer;
|
||||
|
||||
&:has(.bb-picker-body-lunar-text):hover {
|
||||
color: var(--bb-picker-panel-today-color);
|
||||
|
||||
&:before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 33px;
|
||||
height: 33px;
|
||||
border-radius: var(--bs-border-radius);
|
||||
background-color: var(--bb-picker-panel-today-bg);
|
||||
top: 3px;
|
||||
left: -3.5px;
|
||||
opacity: .8;
|
||||
}
|
||||
|
||||
.bb-picker-body-lunar-text {
|
||||
color: var(--bb-picker-panel-today-color);
|
||||
}
|
||||
}
|
||||
|
||||
span.is-holiday {
|
||||
background-color: #c0c4cc;
|
||||
color: var(--bb-picker-panel-today-color);
|
||||
height: 14px;
|
||||
width: 15px;
|
||||
font-size: 9px;
|
||||
border-radius: 3px;
|
||||
top: -1px;
|
||||
right: -9px;
|
||||
line-height: 14px;
|
||||
opacity: .8;
|
||||
}
|
||||
}
|
||||
|
||||
&.today {
|
||||
@@ -141,19 +174,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
&:not(.next-month):not(.prev-month):not(.disabled) {
|
||||
&:not(.next-month):not(.prev-month):not(.disabled):not(.current) {
|
||||
.cell {
|
||||
&.is-solar-term {
|
||||
&.is-solar-term:not(:hover) {
|
||||
.bb-picker-body-lunar-text {
|
||||
color: var(--bs-success);
|
||||
}
|
||||
}
|
||||
|
||||
&.is-festival {
|
||||
&.is-festival:not(:hover) {
|
||||
.bb-picker-body-lunar-text {
|
||||
color: var(--bs-info);
|
||||
}
|
||||
}
|
||||
|
||||
span.is-holiday {
|
||||
background-color: var(--bs-danger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,11 +275,6 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
span {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.bb-picker-body-lunar-text {
|
||||
top: 22px;
|
||||
white-space: nowrap;
|
||||
@@ -250,6 +282,11 @@
|
||||
height: 9px;
|
||||
font-size: 9px;
|
||||
}
|
||||
|
||||
span {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,7 +306,7 @@
|
||||
}
|
||||
|
||||
.picker-panel-footer {
|
||||
border-top: 1px solid #e4e4e4;
|
||||
border-top: var(--bs-border-width) solid var(--bs-border-color);
|
||||
padding: 4px;
|
||||
background-color: #fff;
|
||||
position: relative;
|
||||
@@ -281,7 +318,7 @@
|
||||
padding: 4px 12px;
|
||||
font-size: 0.75rem;
|
||||
border-radius: var(--bs-border-radius);
|
||||
border: 1px solid #dcdfe6;
|
||||
border: var(--bs-border-width) solid var(--bs-border-color);
|
||||
color: #606266;
|
||||
transition: border-color .3s linear, color .3s linear;
|
||||
|
||||
|
||||
@@ -15,4 +15,8 @@
|
||||
{
|
||||
@Template(Value)
|
||||
}
|
||||
@if(ShowHolidays && CalendarHolidays.IsHoliday(Value))
|
||||
{
|
||||
<span class="is-holiday">休</span>
|
||||
}
|
||||
</span>
|
||||
|
||||
@@ -59,9 +59,19 @@ public sealed partial class DatePickerCell
|
||||
[Parameter]
|
||||
public bool ShowFestivals { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否显示休假日 默认 false
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool ShowHolidays { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private ICalendarFestivals? CalendarFestivals { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private ICalendarHolidays? CalendarHolidays { get; set; }
|
||||
|
||||
private string GetLunarText(DateTime dateTime) => dateTime.ToLunarText(ShowSolarTerm, ShowFestivals ? CalendarFestivals : null);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
}
|
||||
<DatePickerBody @bind-Value="SelectedValue" ShowClearButton="AllowNull" ShowSidebar="ShowSidebar" SidebarTemplate="SidebarTemplate"
|
||||
DateTimeFormat="@DateTimeFormat" DateFormat="@DateFormat" TimeFormat="@TimeFormat" ShowFooter="true"
|
||||
ShowLunar="ShowLunar" ShowSolarTerm="ShowSolarTerm" ShowFestivals="ShowFestivals"
|
||||
ShowLunar="ShowLunar" ShowSolarTerm="ShowSolarTerm" ShowFestivals="ShowFestivals" ShowHolidays="ShowHolidays"
|
||||
OnConfirm="OnConfirm" OnClear="OnClear" MinValue="MinValue" MaxValue="MaxValue"
|
||||
AutoClose="AutoClose" ViewMode="ViewMode" DayTemplate="DayTemplate!" DayDisabledTemplate="DayDisabledTemplate!">
|
||||
@ChildContent
|
||||
|
||||
@@ -203,6 +203,12 @@ public partial class DateTimePicker<TValue>
|
||||
[Parameter]
|
||||
public bool ShowFestivals { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否显示休假日 默认 false
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool ShowHolidays { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IStringLocalizer<DateTimePicker<DateTime>>? Localizer { get; set; }
|
||||
|
||||
@@ -44,9 +44,12 @@ public static class BootstrapBlazorServiceCollectionExtensions
|
||||
services.AddSingleton<IIpLocatorProvider, BaiduIpLocatorProvider>();
|
||||
services.AddSingleton<IIpLocatorProvider, BaiduIpLocatorProviderV2>();
|
||||
|
||||
// 节假日服务
|
||||
// 节日服务
|
||||
services.TryAddSingleton<ICalendarFestivals, DefaultCalendarFestivals>();
|
||||
|
||||
// 假日服务
|
||||
services.TryAddSingleton<ICalendarHolidays, DefaultCalendarHolidays>();
|
||||
|
||||
services.TryAddScoped(typeof(IDataService<>), typeof(NullDataService<>));
|
||||
services.TryAddScoped<IReconnectorProvider, ReconnectorProvider>();
|
||||
services.TryAddScoped<IGeoLocationService, DefaultGeoLocationService>();
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
|
||||
namespace BootstrapBlazor.Components;
|
||||
|
||||
class DefaultCalendarFestivals : ICalendarFestivals
|
||||
|
||||
17
src/BootstrapBlazor/Services/DefaultCalendarHolidayss.cs
Normal file
17
src/BootstrapBlazor/Services/DefaultCalendarHolidayss.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
namespace BootstrapBlazor.Components;
|
||||
|
||||
class DefaultCalendarHolidays : ICalendarHolidays
|
||||
{
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsHoliday(DateTime dt)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace BootstrapBlazor.Components;
|
||||
|
||||
/// <summary>
|
||||
/// 中国节假日接口
|
||||
/// 节日接口
|
||||
/// </summary>
|
||||
public interface ICalendarFestivals
|
||||
{
|
||||
|
||||
17
src/BootstrapBlazor/Services/ICalendarHolidays.cs
Normal file
17
src/BootstrapBlazor/Services/ICalendarHolidays.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
namespace BootstrapBlazor.Components;
|
||||
|
||||
/// <summary>
|
||||
/// 休假接口
|
||||
/// </summary>
|
||||
public interface ICalendarHolidays
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得 节假日键值对
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool IsHoliday(DateTime dt);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>8.0.0-beta01</Version>
|
||||
<PackageTags>Bootstrap Blazor WebAssembly wasm UI Components Holidays</PackageTags>
|
||||
<Description>Bootstrap UI components extensions of ICalendarHolidays</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="Data\*.json" />
|
||||
<EmbeddedResource Include="Data\*.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\BootstrapBlazor\BootstrapBlazor.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,69 @@
|
||||
[
|
||||
{
|
||||
"name": "元旦",
|
||||
"range": ["2016-01-01", "2016-01-03"],
|
||||
"type": "holiday"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2016-02-06"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2016-02-07", "2016-02-13"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2016-02-14"],
|
||||
"type": "workingday"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2016-04-02", "2016-04-04"],
|
||||
"type": "holiday"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2016-04-30", "2016-05-02"],
|
||||
"type": "holiday"
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2016-06-09", "2016-06-11"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2016-06-12"],
|
||||
"type": "workingday"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "中秋节",
|
||||
"range": ["2016-09-15", "2016-09-17"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节",
|
||||
"range": ["2016-09-18"],
|
||||
"type": "workingday"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2016-10-01", "2016-10-07"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2016-10-08", "2016-10-09"],
|
||||
"type": "workingday"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,57 @@
|
||||
[
|
||||
{
|
||||
"name": "元旦",
|
||||
"range": ["2016-12-31", "2017-01-02"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2017-01-22"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2017-01-27", "2017-02-02"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2017-02-04"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2017-04-01"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2017-04-02", "2017-04-04"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2017-04-29", "2017-05-01"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2017-05-27"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2017-05-28", "2017-05-30"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2017-09-30"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节、中秋节",
|
||||
"range": ["2017-10-01", "2017-10-08"],
|
||||
"type": "holiday"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,62 @@
|
||||
[
|
||||
{
|
||||
"name": "元旦",
|
||||
"range": ["2017-12-30", "2018-01-01"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2018-02-11"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2018-02-15", "2018-02-21"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2018-02-24"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2018-04-05", "2018-04-07"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2018-04-08"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2018-04-28"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2018-04-29", "2018-05-01"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2018-06-16", "2018-06-18"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节",
|
||||
"range": ["2018-09-22", "2018-09-24"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2018-09-29","2018-09-30"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2018-10-01", "2018-10-07"],
|
||||
"type": "holiday"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,67 @@
|
||||
[
|
||||
{
|
||||
"name": "元旦",
|
||||
"range": ["2018-12-29"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "元旦",
|
||||
"range": ["2018-12-30", "2019-01-01"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2019-02-02", "2019-02-03"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2019-02-04", "2019-02-10"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2019-04-05", "2019-04-07"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2019-04-28"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2019-05-01", "2019-05-04"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2019-05-05"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2019-06-07", "2019-06-09"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节",
|
||||
"range": ["2019-09-13", "2019-09-15"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2019-09-29"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2019-10-01", "2019-10-07"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2019-10-12"],
|
||||
"type": "workingday"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,67 @@
|
||||
[
|
||||
{
|
||||
"name": "元旦",
|
||||
"range": ["2020-01-01"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2020-01-19"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2020-01-24", "2020-01-30"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2020-02-01"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2020-04-04", "2020-04-06"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2020-04-26"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2020-05-01", "2020-05-05"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2020-05-09"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2020-06-25", "2020-06-27"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2020-06-28"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节/国庆节",
|
||||
"range": ["2020-09-27"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节/国庆节",
|
||||
"range": ["2020-10-01", "2020-10-08"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节/国庆节",
|
||||
"range": ["2020-10-10"],
|
||||
"type": "workingday"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,72 @@
|
||||
[
|
||||
{
|
||||
"name": "元旦",
|
||||
"range": ["2021-01-01", "2021-01-03"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2021-02-07"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2021-02-11", "2021-02-17"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2021-02-20"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2021-04-03", "2021-04-05"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2021-04-25"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2021-05-01", "2021-05-05"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2021-05-08"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2021-06-12", "2021-06-14"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节",
|
||||
"range": ["2021-09-18"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节",
|
||||
"range": ["2021-09-19", "2021-09-21"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2021-09-26"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2021-10-01", "2021-10-07"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2021-10-09"],
|
||||
"type": "workingday"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,62 @@
|
||||
[
|
||||
{
|
||||
"name": "元旦",
|
||||
"range": ["2022-01-01", "2022-01-03"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2022-01-29", "2022-01-30"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2022-01-31", "2022-02-06"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2022-04-02"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2022-04-03", "2022-04-05"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2022-04-24"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2022-04-30", "2022-05-04"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2022-05-07"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2022-06-03", "2022-06-05"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节",
|
||||
"range": ["2022-09-10", "2022-09-12"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2022-10-01", "2022-10-07"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2022-10-08", "2022-10-09"],
|
||||
"type": "workingday"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,57 @@
|
||||
[
|
||||
{
|
||||
"name": "元旦",
|
||||
"range": ["2022-12-31", "2023-01-02"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2023-01-21", "2023-01-27"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2023-01-28", "2023-01-29"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2023-04-05"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2023-04-23"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2023-04-29", "2023-05-03"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2023-05-06"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2023-06-22", "2023-06-24"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2023-06-25"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节/国庆节",
|
||||
"range": ["2023-09-29", "2023-10-06"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节/国庆节",
|
||||
"range": ["2023-10-07", "2023-10-08"],
|
||||
"type": "workingday"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,77 @@
|
||||
[
|
||||
{
|
||||
"name": "元旦",
|
||||
"range": ["2023-12-30", "2024-01-01"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2024-02-04"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2024-02-10", "2024-02-17"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "春节",
|
||||
"range": ["2024-02-18"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2024-04-04", "2024-04-06"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "清明节",
|
||||
"range": ["2024-04-07"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2024-04-28"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2024-05-01", "2024-05-05"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "劳动节",
|
||||
"range": ["2024-05-11"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "端午节",
|
||||
"range": ["2024-06-08", "2024-06-10"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节",
|
||||
"range": ["2024-09-14"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "中秋节",
|
||||
"range": ["2024-09-15", "2024-09-17"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2024-09-29"],
|
||||
"type": "workingday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2024-10-01", "2024-10-07"],
|
||||
"type": "holiday"
|
||||
},
|
||||
{
|
||||
"name": "国庆节",
|
||||
"range": ["2024-10-12"],
|
||||
"type": "workingday"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
using BootstrapBlazor.Components;
|
||||
using BootstrapBlazor.Holiday.Services;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// BootstrapBlazor 服务扩展类
|
||||
/// </summary>
|
||||
public static class BootstrapBlazorAzureOpenAIServiceExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加 AzureOpenAIService 服务
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public static IServiceCollection AddBootstrapHolidayService(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<ICalendarHolidays, DefaultCalendarHolidays>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
using BootstrapBlazor.Components;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace BootstrapBlazor.Holiday.Services;
|
||||
|
||||
class DefaultCalendarHolidays : ICalendarHolidays
|
||||
{
|
||||
public DefaultCalendarHolidays()
|
||||
{
|
||||
var option = new JsonSerializerOptions(JsonSerializerDefaults.Web);
|
||||
var assembly = GetType().Assembly;
|
||||
foreach (var file in assembly.GetManifestResourceNames())
|
||||
{
|
||||
using var stream = assembly.GetManifestResourceStream(file);
|
||||
if (stream != null)
|
||||
{
|
||||
var items = JsonSerializer.Deserialize(stream, typeof(List<HolidayItem>), option);
|
||||
if (items is List<HolidayItem> list)
|
||||
{
|
||||
_holidays.AddRange(list.Where(i => i.Type == "holiday"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<HolidayItem> _holidays = new();
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
public bool IsHoliday(DateTime dt) => _holidays.Find(i => FindHoliday(i, dt)) != null;
|
||||
|
||||
private static bool FindHoliday(HolidayItem item, DateTime value)
|
||||
{
|
||||
var ret = false;
|
||||
if (item.Range != null)
|
||||
{
|
||||
if (item.Range.Count == 1 && DateTime.TryParseExact(item.Range[0], "yyyy-MM-dd", null, DateTimeStyles.None, out var v))
|
||||
{
|
||||
ret = v == value;
|
||||
}
|
||||
else if (item.Range.Count == 2
|
||||
&& DateTime.TryParseExact(item.Range[0], "yyyy-MM-dd", null, DateTimeStyles.None, out var v1)
|
||||
&& DateTime.TryParseExact(item.Range[1], "yyyy-MM-dd", null, DateTimeStyles.None, out var v2))
|
||||
{
|
||||
ret = value >= v1 && value <= v2;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
class HolidayItem
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
||||
public List<string>? Range { get; set; }
|
||||
|
||||
public string? Type { get; set; }
|
||||
}
|
||||
}
|
||||
BIN
src/Extensions/Components/BootstrapBlazor.Holiday/logo.png
Normal file
BIN
src/Extensions/Components/BootstrapBlazor.Holiday/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
@@ -3,6 +3,7 @@
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
using AngleSharp.Dom;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace UnitTest.Components;
|
||||
|
||||
@@ -353,6 +354,40 @@ public class DateTimePickerTest : BootstrapBlazorTestBase
|
||||
cut.Contains("闰二月");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShowHolidays_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<DateTimePicker<DateTime>>(pb =>
|
||||
{
|
||||
pb.Add(a => a.ShowHolidays, true);
|
||||
pb.Add(a => a.Value, new DateTime(2024, 3, 5));
|
||||
});
|
||||
cut.DoesNotContain("休");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShowHolidays_Custom()
|
||||
{
|
||||
var context = new TestContext();
|
||||
context.JSInterop.Mode = JSRuntimeMode.Loose;
|
||||
|
||||
var services = context.Services;
|
||||
services.AddBootstrapBlazor();
|
||||
services.AddSingleton<ICalendarHolidays, MockCalendarHolidayService>();
|
||||
|
||||
var cut = context.RenderComponent<DateTimePicker<DateTime>>(pb =>
|
||||
{
|
||||
pb.Add(a => a.ShowHolidays, true);
|
||||
pb.Add(a => a.Value, new DateTime(2024, 3, 17));
|
||||
});
|
||||
cut.Contains("休");
|
||||
}
|
||||
|
||||
class MockCalendarHolidayService : ICalendarHolidays
|
||||
{
|
||||
public bool IsHoliday(DateTime dt) => dt == new DateTime(2024, 3, 17);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DayTemplate_Ok()
|
||||
{
|
||||
|
||||
21
test/UnitTestHoliday/UnitTest1.cs
Normal file
21
test/UnitTestHoliday/UnitTest1.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace UnitTestHoliday;
|
||||
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddBootstrapHolidayService();
|
||||
|
||||
var provider = services.BuildServiceProvider();
|
||||
var holidayService = provider.GetRequiredService<ICalendarHolidays>();
|
||||
Assert.True(holidayService.IsHoliday(new DateTime(2016, 01, 01)));
|
||||
}
|
||||
}
|
||||
26
test/UnitTestHoliday/UnitTestHoliday.csproj
Normal file
26
test/UnitTestHoliday/UnitTestHoliday.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="bunit" Version="1.27.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||
<PackageReference Include="xunit" Version="2.7.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Remove="UnitTest.Core" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Extensions\Components\BootstrapBlazor.Holiday\BootstrapBlazor.Holiday.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user