98 lines
3.4 KiB
C#
98 lines
3.4 KiB
C#
using System;
|
|
|
|
namespace Falcon.SugarApi.TimedTask
|
|
{
|
|
public class CronResult
|
|
{
|
|
public DateTime AdjustTime { get; set; }
|
|
public bool IsYearAdjust { get; set; } = false;
|
|
public bool IsMonthAdjust { get; set; } = false;
|
|
public bool IsDayAdjust { get; set; } = false;
|
|
public bool IsDayOfWeekAdjust { get; set; } = false;
|
|
public bool IsHourAdjust { get; set; } = false;
|
|
public bool IsMinuteAdjust { get; set; } = false;
|
|
public bool IsSecondAdjust { get; set; } = false;
|
|
|
|
public bool IsAllAdjust
|
|
=> (IsYearAdjust && IsMonthAdjust && IsDayAdjust && IsDayOfWeekAdjust
|
|
&& IsHourAdjust && IsMinuteAdjust && IsSecondAdjust) || IsNullVal;
|
|
|
|
/// <summary>
|
|
/// 没有匹配到值
|
|
/// </summary>
|
|
public bool IsNullVal { get; set; } = false;
|
|
|
|
public CronResult(DateTime last) => this.AdjustTime = last;
|
|
|
|
public void SetAdjustTime(DateTime dt,TimePartEnum part) {
|
|
if(!part.HasFlag(TimePartEnum.Year)) {
|
|
return;
|
|
}
|
|
if(dt.Year != this.AdjustTime.Year) {
|
|
this.AdjustTime = new DateTime(dt.Year,1,1,0,0,0);
|
|
IsYearAdjust = false;
|
|
IsMonthAdjust = false;
|
|
IsDayAdjust = false;
|
|
IsDayOfWeekAdjust = false;
|
|
IsHourAdjust = false;
|
|
IsMinuteAdjust = false;
|
|
IsSecondAdjust = false;
|
|
return;
|
|
}
|
|
if(!part.HasFlag(TimePartEnum.Month)) {
|
|
return;
|
|
}
|
|
if(dt.Month != this.AdjustTime.Month) {
|
|
this.AdjustTime = new DateTime(dt.Year,dt.Month,1,0,0,0);
|
|
IsMonthAdjust = false;
|
|
IsDayAdjust = false;
|
|
IsDayOfWeekAdjust = false;
|
|
IsHourAdjust = false;
|
|
IsMinuteAdjust = false;
|
|
IsSecondAdjust = false;
|
|
return;
|
|
}
|
|
if(!part.HasFlag(TimePartEnum.Day)) {
|
|
return;
|
|
}
|
|
if(dt.Day != this.AdjustTime.Day) {
|
|
this.AdjustTime = new DateTime(dt.Year,dt.Month,dt.Day,0,0,0);
|
|
IsDayAdjust = false;
|
|
IsDayOfWeekAdjust = false;
|
|
IsHourAdjust = false;
|
|
IsMinuteAdjust = false;
|
|
IsSecondAdjust = false;
|
|
return;
|
|
}
|
|
if(!part.HasFlag(TimePartEnum.Hour)) {
|
|
return;
|
|
}
|
|
if(dt.Hour != this.AdjustTime.Hour) {
|
|
this.AdjustTime = new DateTime(dt.Year,dt.Month,dt.Day,dt.Hour,0,0);
|
|
IsHourAdjust = false;
|
|
IsMinuteAdjust = false;
|
|
IsSecondAdjust = false;
|
|
return;
|
|
}
|
|
if(!part.HasFlag(TimePartEnum.Minute)) {
|
|
return;
|
|
}
|
|
if(dt.Minute != this.AdjustTime.Minute) {
|
|
this.AdjustTime = new DateTime(dt.Year,dt.Month,dt.Day,dt.Hour,dt.Minute,0);
|
|
IsMinuteAdjust = false;
|
|
IsSecondAdjust = false;
|
|
return;
|
|
}
|
|
if(!part.HasFlag(TimePartEnum.Second)) {
|
|
return;
|
|
}
|
|
if(dt.Second != this.AdjustTime.Second) {
|
|
this.AdjustTime = dt;
|
|
IsSecondAdjust = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|