feat 跳板机中间api
This commit is contained in:
42
Src/Dlhis.Middle/TimePeriodExtensions.cs
Normal file
42
Src/Dlhis.Middle/TimePeriodExtensions.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
|
||||
namespace Dlhis.Middle;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 临时的扩展类 todo: 嵌入框架
|
||||
/// </summary>
|
||||
public static class TimePeriodExtensions
|
||||
{
|
||||
public static bool IsPresent1(this TimePeriod period, DateTime dateTime)
|
||||
{
|
||||
DateTime start;
|
||||
DateTime end;
|
||||
|
||||
if (period.IsCrossDay())
|
||||
{
|
||||
//period = [22:00:00,03:00:00]
|
||||
var currentStart = dateTime.Date.Add(period.Start.Value.ToTimeSpan());
|
||||
var endOfDay = dateTime.Date.AddDays(1).AddSeconds(-1);
|
||||
|
||||
//assume is left range . then currentStart is 2024-04-16 22:00:00 and endOfDay is 2024-04-16 23:59:59
|
||||
if (dateTime >= currentStart && dateTime <= endOfDay)
|
||||
{
|
||||
start = currentStart; //2024-04-16 22:00:00
|
||||
end = dateTime.Date.AddDays(1).Add(period.End.Value.ToTimeSpan());//2024-04-17 03:00:00
|
||||
}
|
||||
else
|
||||
{
|
||||
start = dateTime.Date.AddDays(-1).Add(period.Start.Value.ToTimeSpan());
|
||||
end = dateTime.Date.Add(period.End.Value.ToTimeSpan());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
start = dateTime.Date.Add(period.Start.Value.ToTimeSpan());
|
||||
end = dateTime.Date.Add(period.End.Value.ToTimeSpan());
|
||||
}
|
||||
|
||||
return dateTime >= start && dateTime <= end;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user