public bool IsTrigger(DateTime currDate, int secondInterval) { if (currDate < StartDate || currDate >= StopDate || secondInterval <= 0) { return(false); } bool result = false; var excuteDate = PreExcuteDate == DateTime.MinValue ? StartDate : PreExcuteDate.AddSeconds(secondInterval); var nextExcuteDate = excuteDate.AddSeconds(secondInterval); //string info = string.Empty; if (currDate < PreExcuteDate || currDate >= nextExcuteDate) { //修正当前时间位置 var ts = StopDate - StartDate; var numberTimes = (int)ts.TotalSeconds / secondInterval; int times = FindIntervalTimes(currDate, 0, numberTimes, secondInterval); PreExcuteDate = StartDate.AddSeconds(secondInterval * (times - 1)); excuteDate = PreExcuteDate.AddSeconds(secondInterval); nextExcuteDate = excuteDate.AddSeconds(secondInterval); } //info = string.Format("{0}>>timing pre:{1}, cur:{2}, next:{3}", _config.Name, PreExcuteDate, excuteDate, nextExcuteDate); if (excuteDate <= currDate && currDate < nextExcuteDate) { PreExcuteDate = excuteDate; result = currDate < excuteDate.AddMilliseconds(TimeListener.OffsetMillisecond);//整点处理 } //if (result) //{ // TraceLog.WriteInfo(info); //} return(result); }
private int FindIntervalTimes(DateTime currDate, int startIndex, int endIndex, int secondInterval) { int index = -1; while (endIndex >= startIndex) { int middle = (startIndex + endIndex) / 2; int nextMiddle = middle + 1; var value = StartDate.AddSeconds(middle * secondInterval); var nextValue = StartDate.AddSeconds(nextMiddle * secondInterval); int result = value.CompareTo(currDate); if (result <= 0 && (nextValue.CompareTo(currDate) > 0)) { index = result == 0 ? middle : middle + 1; break; } else if (result > 0) { endIndex = middle - 1; } else { startIndex = middle + 1; } } return(index); }
public DateTime StartTime() { if (StartDate.AddSeconds(-PrePaddingSeconds + 1) < DateTime.UtcNow) { return(DateTime.UtcNow.AddSeconds(1)); } return(StartDate.AddSeconds(-PrePaddingSeconds)); }
private void doMovement() { integrator.MoveOrbiters(dt); rotate(); totalElapsedTime += dt; Date = StartDate.AddSeconds(totalElapsedTime); // less error than Date.AddSeconds(dt)? ExternalDate = Date; Frames++; }
public bool IsTriggerStart(DateTime currDate) { if (currDate >= StartDate && currDate < StartDate.AddSeconds(OffsetSecond)) { PreDate = currDate; IsEnd = true; return(true); } return(false); }
public DataTimeParamViewModel() { StartDate = StartDate.AddSeconds(StartTime); EndDate = EndDate.AddSeconds(StartTime); if (StartDate > DateTime.Now) { StartDate = StartDate.AddDays(-1); EndDate = EndDate.AddDays(-1); } }
public bool IsTrigger(DateTime currDate, int secondInterval) { if (currDate < StartDate || currDate >= StopDate || secondInterval <= 0) { return(false); } bool result = false; var excuteDate = PreDate == DateTime.MinValue ? StartDate : PreDate.AddSeconds(secondInterval); var nextExcuteDate = excuteDate.AddSeconds(secondInterval); if (currDate < PreDate || currDate >= nextExcuteDate) { //修正当前时间位置 var ts = StopDate - StartDate; var numberTimes = (int)ts.TotalSeconds / secondInterval; int times = FindIntervalTimes(currDate, 0, numberTimes, secondInterval); PreDate = StartDate.AddSeconds(secondInterval * (times - 1)); excuteDate = PreDate.AddSeconds(secondInterval); nextExcuteDate = excuteDate.AddSeconds(secondInterval); } //Trace.WriteLine(string.Format("timing pre:{0}, cur:{1}, next:{2}", PreDate, currDate, excuteDate)); if (PreDate <= currDate && currDate < excuteDate) { //时间还没有到 } else if (excuteDate <= currDate && currDate < nextExcuteDate) { PreDate = excuteDate; result = currDate < excuteDate.AddSeconds(OffsetSecond);//整点处理 } else { } return(result); }
private static DateTime SetDateWithChecks(DateTime obj, int year, int month, int day, int?hour, int?minute, int?second, int?millisecond) { DateTime StartDate; if (year == 0) { StartDate = new DateTime(obj.Year, 1, 1, 0, 0, 0, 0); } else { if (DateTime.MaxValue.Year < year) { StartDate = new DateTime(DateTime.MinValue.Year, 1, 1, 0, 0, 0, 0); } else if (DateTime.MinValue.Year > year) { StartDate = new DateTime(DateTime.MaxValue.Year, 1, 1, 0, 0, 0, 0); } else { StartDate = new DateTime(year, 1, 1, 0, 0, 0, 0); } } if (month == 0) { StartDate = StartDate.AddMonths(obj.Month - 1); } else { StartDate = StartDate.AddMonths(month - 1); } if (day == 0) { StartDate = StartDate.AddDays(obj.Day - 1); } else { StartDate = StartDate.AddDays(day - 1); } if (!hour.HasValue) { StartDate = StartDate.AddHours(obj.Hour); } else { StartDate = StartDate.AddHours(hour.Value); } if (!minute.HasValue) { StartDate = StartDate.AddMinutes(obj.Minute); } else { StartDate = StartDate.AddMinutes(minute.Value); } if (!second.HasValue) { StartDate = StartDate.AddSeconds(obj.Second); } else { StartDate = StartDate.AddSeconds(second.Value); } if (!millisecond.HasValue) { StartDate = StartDate.AddMilliseconds(obj.Millisecond); } else { StartDate = StartDate.AddMilliseconds(millisecond.Value); } return(StartDate); }