/// <summary> /// Contains 目标时刻是否在时间范围内 /// </summary> public bool Contains(ShortTime target) { bool bStart = this.shortTimeStart.CompareTo(target) <= 0; bool bEnd = this.shortTimeEnd.CompareTo(target) >= 0; return(bStart && bEnd); }
public ShortTimeScope(ShortTime first, ShortTime later) { this.shortTimeStart = first; this.shortTimeEnd = later; if (first.CompareTo(later) >= 0) { throw new Exception("the parameter later must be greatter than first!"); } }
public bool IsOnTime(int checkSpanSeconds, DateTime now) { #region 防止在临界点时,执行两次 TimeSpan span = now - this.lastRightTime; if (span.TotalMilliseconds < checkSpanSeconds * 1000 * 2) { return(false); } #endregion bool isOnTime = false; #region Switch switch (this.timingTaskType) { case TimingTaskType.PerHour: { ShortTime temp = new ShortTime(now.Hour, this.excuteTime.Minute, this.excuteTime.Second); isOnTime = temp.IsOnTime(now, checkSpanSeconds); if (!isOnTime) { ShortTime temp2 = new ShortTime(now.AddHours(1).Hour, this.excuteTime.Minute, this.excuteTime.Second); isOnTime = temp2.IsOnTime(now, checkSpanSeconds); } if (!isOnTime) { ShortTime temp3 = new ShortTime(now.AddHours(-1).Hour, this.excuteTime.Minute, this.excuteTime.Second); isOnTime = temp3.IsOnTime(now, checkSpanSeconds); } break; } case TimingTaskType.PerDay: { isOnTime = this.excuteTime.IsOnTime(now, checkSpanSeconds); break; } case TimingTaskType.PerWeek: { if (now.DayOfWeek != this.dayOfWeek) { isOnTime = false; } else { isOnTime = this.excuteTime.IsOnTime(now, checkSpanSeconds); } break; } case TimingTaskType.PerMonth: { if (now.Day != this.day) { isOnTime = false; } else { isOnTime = this.excuteTime.IsOnTime(now, checkSpanSeconds); } break; } default: { break; } } #endregion if (isOnTime) { this.lastRightTime = now; } return(isOnTime); }