public override DateTime Next(DateTime time, out bool changed) { changed = false; if (Values.Count < 1) { return time; } if (Type == CGtd.DATES_TYPE_EACH) { return time.AddMinutes(Values[0]); } if (Type == CGtd.DATES_TYPE_WHEN) { int idx = time.Minute; int tmp = NextValue(idx, changed); if (tmp > 0) { return time.AddMinutes(tmp); } if (tmp < 0) { changed = true; return time.AddHours(1).AddMinutes(Values[0] - idx); } } return time; }
public static WeatherLocatioinModel LoadLocationWeatherData(DateTime now, Location location, WeatherData[] locationData) { var minDate = now.AddMinutes(-90); var maxDate = now.AddMinutes(90); // погода на текущее время var current = locationData.FirstOrDefault(d => d.Date > minDate && d.Date <= maxDate); // погода на ближайшие сутки var xxx = current != null ? current.Date : now; var day = locationData .Where(d => d.Date > xxx && d.Date <= xxx.AddDays(1)) .Where(FilterByHours) .OrderBy(d => d.Date) .Take(3) .ToArray(); // прогноз на несколько дней var forecast = locationData .Where(d => d.Date.Date > now.Date) .GroupBy(d => d.Date.Date) .Take(3); return new WeatherLocatioinModel { LocationId = location.Id, LocationName = location.DisplayName, Now = CreateNowModel(current), Today = day.Select(CreateNowModel).ToArray(), Forecast = forecast.Select(CreateDayModel).ToArray() }; }
public static bool CompareDate(DateTime dateToCompare, DateTime date, int minuteTolerance) { if (!dateToCompare.Equals(date)) { date = date.AddMinutes(minuteTolerance); if (!dateToCompare.Equals(date)) { date = date.AddMinutes(-2 * minuteTolerance); if (!dateToCompare.Equals(date)) { return false; } else { return true; } } else { return true; } } else { return true; } }
/// <summary> /// 作者:Beta /// 时间:2014.03.17 /// 描述:获取样式列表(需求展示) /// </summary> /// <param name="list"></param> /// <param name="dt"></param> /// <returns></returns> public static string GetStudentClassList(List<Model.Eme.BookRequirement> list, DateTime dt) { var classlist = " select-item"; if (dt.AddHours(-1) < DateTime.Now) { if (list.Any(p => p.BookStartTime <= dt && p.BookEndTime >= dt.AddMinutes(30) && p.IsSuccessful)) { classlist = classlist + " successful"; } else if (list.Any(p => p.BookStartTime <= dt && p.BookEndTime >= dt.AddMinutes(30) && !p.IsSuccessful)) { classlist = classlist + " pass"; } else { classlist = classlist + " unavailable"; } } else { if (list.Any(p => p.BookStartTime <= dt && p.BookEndTime >= dt.AddMinutes(30) && p.IsSuccessful)) { classlist = classlist + " successful"; } else if (list.Any(p => p.BookStartTime <= dt && p.BookEndTime >= dt.AddMinutes(30) && !p.IsSuccessful)) { classlist = classlist + " normal oking"; } } return classlist; }
/// <summary> /// Returns the date that is 30 minutes before or after input date if input date minute is 0 or 30. Otherwise it returns next increment to 0 or 30. /// </summary> /// <param name="date">Date and time.</param> /// <param name="forward">Indicates whether to add or subtract minutes.</param> /// <returns>New date time.</returns> public static DateTime GetNext30Minute(DateTime date, bool forward) { if (date.Minute == 0 || date.Minute == 30) return (date.AddMinutes(forward ? 30 : -30)); return (date.AddMinutes((forward ? 1 : -1) * Math.Abs(30 - date.Minute))); }
public void UpdatesAfterCorrectPeriodElapses() { const int periods = 3; var periodSpan = Time.OneMinute; var reference = new DateTime(2016, 04, 06, 12, 0, 0); var referenceUtc = reference.ConvertToUtc(TimeZones.NewYork); var timeKeeper = new TimeKeeper(referenceUtc); var config = new SubscriptionDataConfig(typeof (TradeBar), Symbols.SPY, Resolution.Minute, TimeZones.NewYork, TimeZones.NewYork, true, false, false); var security = new Security(SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), config, new Cash("USD", 0, 0), SymbolProperties.GetDefault("USD")); security.SetLocalTimeKeeper(timeKeeper.GetLocalTimeKeeper(TimeZones.NewYork)); var model = new RelativeStandardDeviationVolatilityModel(periodSpan, periods); security.VolatilityModel = model; var first = new IndicatorDataPoint(reference, 1); security.SetMarketPrice(first); Assert.AreEqual(0m, model.Volatility); const decimal value = 0.471404520791032M; // std of 1,2 is ~0.707 over a mean of 1.5 var second = new IndicatorDataPoint(reference.AddMinutes(1), 2); security.SetMarketPrice(second); Assert.AreEqual(value, model.Volatility); // update should not be applied since not enough time has passed var third = new IndicatorDataPoint(reference.AddMinutes(1.01), 1000); security.SetMarketPrice(third); Assert.AreEqual(value, model.Volatility); var fourth = new IndicatorDataPoint(reference.AddMinutes(2), 3m); security.SetMarketPrice(fourth); Assert.AreEqual(0.5m, model.Volatility); }
// Validates to check if teams in a match are available for a given time public bool areTeamsFree(Match m, DateTime startTime) { // Start time can not be earlier than the tournament stage start time if (m.TournamentStage.TimeInterval.StartTime > startTime) { return false; } foreach (Team team in m.Teams) { // Get the time interval for a team and for the parameter date TimeInterval timesForDate = team.TimeIntervals.First(x => x.StartTime.Date == startTime.Date); // Start time can not be earlier than teams start time and the match can not end later than a teams end time if (startTime < timesForDate.StartTime || startTime.AddMinutes(m.Duration) > timesForDate.EndTime) { return false; } // Check all the matches for the team foreach (Match match in team.Matches) { if (match.IsScheduled && startTime.AddMinutes(m.Duration * 2) > match.StartTime) { DateTime teamBreakDone = match.StartTime.AddMinutes(match.Duration * 2); if (startTime < teamBreakDone) { return false; } } } } return true; }
public void ReorganizeAdStacks(IDictionary<DateTime, IDictionary<Guid, IDictionary<Ad, IDictionary<int, long>>>> adDispatchPlans, DateTime currentTime) { var time = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, 0); if (adDispatchPlans != null && adDispatchPlans.ContainsKey(time.AddMinutes(-1)) && adDispatchPlans.ContainsKey(time.AddMinutes(1))) { //上一分钟 var lastMeidaAdPlans = adDispatchPlans[time.AddMinutes(-1)]; //下一分钟 var nextMediaAdPlans = adDispatchPlans[time.AddMinutes(1)]; //轮询处理每个媒体的广告 foreach (var lastAdMediaAdPlan in lastMeidaAdPlans.AsParallel()) { var mediaId = lastAdMediaAdPlan.Key; if (!nextMediaAdPlans.ContainsKey(mediaId)) { nextMediaAdPlans[mediaId] = new ConcurrentDictionary<Ad, IDictionary<int, long>>(); } //轮询处理该媒体内每个广告 foreach (var lastAdPlan in lastAdMediaAdPlan.Value) { int i = 0; while (lastAdPlan.Value.ContainsKey(i)) { if (!nextMediaAdPlans[mediaId].ContainsKey(lastAdPlan.Key)) { nextMediaAdPlans[mediaId][lastAdPlan.Key] = new ConcurrentDictionary<int, long>(); } //TODO:对于贴片位置定向的情况需要进行处理 nextMediaAdPlans[mediaId][lastAdPlan.Key][i + 1] = lastAdPlan.Value[i]; i++; } } } } }
private void InsertObjectBlock() { _taskExecution1 = _executionHelper.InsertOverrideTaskExecution(_taskDefinitionId); _baseDateTime = new DateTime(2016, 1, 1); var block1 = _blocksHelper.InsertObjectBlock(_taskDefinitionId, DateTime.UtcNow, Guid.NewGuid().ToString()).ToString(); _blockExecutionId = _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(block1), _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-25), BlockExecutionStatus.Started); }
public DateTime CalcNearestFiveMinTime(DateTime dateIn) { dateIn = dateIn.AddMinutes(-2); int iMin = 5 * (dateIn.Minute / 5); DateTime dateOut = dateIn.AddMinutes(0 - dateIn.Minute).AddMinutes(iMin); return dateOut; }
private static IEnumerable<Interval<DateTime>> GetDateRangesAllDescendingEndTimes(DateTime date, int count) { var dateRanges = new Interval<DateTime>[count]; for (int i = 1; i <= count; i++) { dateRanges[i - 1] = new Interval<DateTime>(date.AddMinutes(-i), date.AddMinutes(i)); } return new List<Interval<DateTime>>(dateRanges).OrderBy(x => x.Min.Value); }
/// <summary> /// 填充没有统计到的时间点 /// </summary> /// <param name="originalDataList"></param> /// <returns></returns> public IEnumerable<ServiceHostStatMinute> Fill(DateTime startDate, IEnumerable<ServiceHostStatMinute> originalDataList) { startDate = DateTime.Parse(startDate.ToString("yyyy-MM-dd HH:mm:00")); var filledDataList = new List<ServiceHostStatMinute>(); for (var i = 2; i <= 31; i++) { var item = originalDataList.FirstOrDefault(m => m.StatTime == startDate.AddMinutes(i * -1)) ?? new ServiceHostStatMinute() { StatTime = startDate.AddMinutes(i * -1) }; filledDataList.Add(item); } return filledDataList; }
public static long InsertBreak(long emp,DateTime start,int minutes) { ClockEvent ce=new ClockEvent(); ce.ClockStatus=TimeClockStatus.Break; ce.EmployeeNum=emp; ce.TimeDisplayed1=start; ce.TimeEntered1=start; ce.TimeDisplayed2=start.AddMinutes(minutes); ce.TimeEntered2=start.AddMinutes(minutes); ce.ClockEventNum = ClockEvents.Insert(ce); ClockEvents.Update(ce);//Updates TimeDisplayed1 because it defaults to now(). return ce.ClockEventNum; }
/// <summary> /// Asserts that the dates are valid. /// </summary> public void AssertDateTimes(DateTime expectedDate, DateTime actualDate, int maxMinutesVariance = 1, string message = "") { if (expectedDate.AddMinutes(maxMinutesVariance) < actualDate) { Assert.Fail(message); } if (actualDate < expectedDate.AddMinutes(-maxMinutesVariance)) { Assert.Fail(message); } }
public InProcSessionCacheFixture() { _nowUtc = new DateTime(2015, 10, 20, 21, 36, 14, DateTimeKind.Utc); _fakeSystemClock = A.Fake<ISystemClock>(); ConfigureSystemClock_ToReturn(_nowUtc); _inProcSessionCache = new InProcSessionCache(_fakeSystemClock); _expiredSession = new InProcSession(new SessionId(Guid.NewGuid(), false), A.Dummy<ISession>(), _nowUtc.AddMinutes(-20), TimeSpan.FromMinutes(15)); _activeSession = new InProcSession(new SessionId(Guid.NewGuid(), false), A.Dummy<ISession>(), _nowUtc.AddMinutes(-3), TimeSpan.FromMinutes(15)); _inProcSessionCache.Set(_expiredSession); _inProcSessionCache.Set(_activeSession); _numberOfSessions = 2; }
public void GetMatches_ReturnsCollectionOfScheduleMatches_BetweenLocalTime_AndLastMatchingTime() { var time = new DateTime(2012, 12, 12, 00, 00, 00, DateTimeKind.Utc); var instant = CreateInstant(time); var matches = instant.GetMatches(time.AddMinutes(-3)).ToList(); Assert.Equal(3, matches.Count); Assert.Equal(time.AddMinutes(-2), matches[0]); Assert.Equal(time.AddMinutes(-1), matches[1]); Assert.Equal(time, matches[2]); }
private static List<KeyValuePair<ServiceTypeModel, Tuple<DateTime, DateTime>>> GetServiceTypesTimeBlocks(DateTime time, IEnumerable<ServiceTypeModel> serviceTypes) { var result = new List<KeyValuePair<ServiceTypeModel, Tuple<DateTime, DateTime>>>(); foreach (var type in serviceTypes) { foreach (var typePhase in type.Phases.OrderBy(x => x.Order)) { var previousPhase = type.Phases.Where(x => x.Order < typePhase.Order); var timeOffset = previousPhase.Sum(x => x.DelayInMinutes) + previousPhase.Sum(x => x.DurationInMinutes); result.Add(new KeyValuePair<ServiceTypeModel, Tuple<DateTime, DateTime>>(type, new Tuple<DateTime, DateTime>(time.AddMinutes(timeOffset), time.AddMinutes(timeOffset + typePhase.DurationInMinutes)))); } } return result; }
public void MinutePeriodTest2() { // 매 10분마다 수행한다. const string PeriodFmt = "0,10,20,30,40,50 * * * *"; var lastTime = new DateTime(2007, 3, 28, 12, 5, 0); var currTime = new DateTime(2007, 3, 28, 12, 9, 55); Assert.IsFalse(PeriodTimeFormat.IsExpired(PeriodFmt, lastTime, currTime)); Assert.IsFalse(PeriodTimeFormat.IsExpired(PeriodFmt, lastTime, currTime.AddSeconds(4))); Assert.IsFalse(PeriodTimeFormat.IsExpired(PeriodFmt, lastTime, currTime.AddMinutes(-5))); Assert.IsTrue(PeriodTimeFormat.IsExpired(PeriodFmt, lastTime, currTime.AddMinutes(1))); Assert.IsTrue(PeriodTimeFormat.IsExpired(PeriodFmt, lastTime.AddMinutes(10), currTime.AddMinutes(11))); }
public NewsReport(string name, string currency, DateTime datetime, int noEntryMinutesPrior, int noEntryMinutesPost, int closeOutMinutesPrior) { this.name = name; this.currency = currency; this.datetime = datetime; this.noEntryMinutesPrior = noEntryMinutesPrior; this.noEntryMinutesPost = noEntryMinutesPost; this.closeOutMinutesPrior = closeOutMinutesPrior; this.noEntryPriorDateTime = datetime.AddMinutes(-noEntryMinutesPrior); this.noEntryPostDateTime = datetime.AddMinutes(noEntryMinutesPost); this.closeOutPriorDateTime = datetime.AddMinutes(-closeOutMinutesPrior); }
private EKAlarm ConvertReminder(AppointmentReminder reminder, DateTime startTime) { switch (reminder) { case AppointmentReminder.none: return EKAlarm.FromDate((NSDate)startTime); ///todo should this be null? case AppointmentReminder.five: return EKAlarm.FromDate((NSDate)startTime.AddMinutes(-5)); case AppointmentReminder.fifteen: return EKAlarm.FromDate((NSDate)startTime.AddMinutes(-15)); case AppointmentReminder.thirty: return EKAlarm.FromDate((NSDate)startTime.AddMinutes(-30)); } return EKAlarm.FromDate((NSDate)startTime); }
public void Should_be_able_to_satisfy_a_stepped_values() { var field = new CronMinute("5-10/5"); var control = new DateTime(2011, 01, 01, 0, 0, 0); var date = field.SnapForward(control); Assert.AreEqual(control.AddMinutes(5), date); date = field.SnapForward(date.AddMinutes(1)); Assert.AreEqual(control.AddMinutes(10), date); date = field.SnapForward(date.AddMinutes(1)); Assert.AreEqual(control.AddMinutes(65), date); }
private string GetICSString(DateTime date, int duration, string name, string location, string shortDescription) { var sb = new StringBuilder(); sb.AppendLine("BEGIN:VCALENDAR"); sb.AppendLine("VERSION:1.0"); sb.AppendLine("BEGIN:VEVENT"); sb.AppendFormat("DTSTART:{0}", GetFormattedTime(date)); sb.AppendLine(); sb.AppendFormat("DTEND:{0}", GetFormattedTime(date.AddMinutes(duration))); sb.AppendLine(); sb.AppendFormat("SUMMARY:{0}", name); sb.AppendLine(); sb.AppendFormat("LOCATION:{0}", location); sb.AppendLine(); string description = shortDescription; if (description.IsEmpty()) { description = name; } sb.AppendFormat("DESCRIPTION:{0}", description.Replace(Environment.NewLine, " ")); sb.AppendLine(); sb.AppendLine("END:VEVENT"); sb.AppendLine("END:VCALENDAR"); return sb.ToString(); }
public UpNextTableSource () { var sessions = BL.Managers.SessionManager.GetSessions (); var now = DateTime.Now; #if DEBUG //TEST: for 'up next' code //now = new DateTime(2012,3,28,9,11,0); now = new DateTime(2012,2,28,9,11,0); #endif var nowStart = now.AddMinutes ( - (now.Minute % 5)); // round to 5 minutes // var happeningNow = from s in sessions // where s.Start <= now // && now < (s.End == DateTime.MinValue ? s.Start.AddHours(1): s.End) // //&& (s.Start.Minute % 10 == 0 || s.Start.Minute % 15 == 0) // fix for short-sessions (which start at :05 after the hour) // select s; // _upnext = happeningNow.ToList(); var nextStart = nowStart.AddMinutes (14); // possible fix to (within 30 minutes bug) nextStart = nextStart.AddSeconds(-nextStart.Second); var allUpcoming = from s in sessions where s.Start >= nextStart //&& (s.Start.Minute % 10 == 0 || s.Start.Minute % 15 == 0) orderby s.Start.Ticks group s by s.Start.Ticks into g select new { Start = g.Key, Sessions = g }; var upnextGroup = allUpcoming.FirstOrDefault (); if (upnextGroup != null) { // conference is over upNext = upnextGroup.Sessions.ToList(); upNextTime = new DateTime(upnextGroup.Start); } }
public string changeDate(string date, char op, long value) { int nHoras = (int)value / 60; int rHoras = (int)value % 60; int nDias = nHoras / 24; int nMeses = (int)value / 24; //int total_minutes = 4000; //int minutes = total_minutes % 60; //int total_hours = total_minutes / 60; //int horas = total_hours % 24; //int total_days = total_hours / 24; //int dias = total_days % 365; //int anos = total_days / 365; //Console.WriteLine(" "+ anos, dias, horas, minutes); DateTime dateValue = new DateTime(2016, 11, 17, 14, 0, 0); //double[] minutes = { 4000 }; long minutes = 4000; Console.WriteLine(dateValue.AddMinutes(minutes)); Console.ReadKey(); return date; }
private void button1_Click(object sender, EventArgs e) { dataGridView1.Visible = false; dataGridView2.Visible = false; DateTime time = new DateTime(); time = time.AddHours(int.Parse(textBox1.Text)); time = time.AddMinutes(int.Parse(textBox2.Text)); t = time; Glades.list_ctrl_train.Clear(); for (int i = 0; i < list_poezdov.Count; i++) { for (int j = 0; j < marshruts.Count; j++) { if (list_poezdov[i].ID == marshruts[j].ID) { list_poezdov[i].last_ostanovka(marshruts[j], time); } } } pictureBox1.Controls.Clear(); glades.create_ctrl(); load_event(Glades.list_ctrl_train); }
public string ConvertToIranTimeString(DateTime Date) { //string zoneId = "Iran Standard Time"; //TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(zoneId); //DateTime result = TimeZoneInfo.ConvertTimeFromUtc(Date, tzi); Date = Date.AddMinutes(-150); PersianCalendar pc = new PersianCalendar(); string year = pc.GetYear(Date).ToString(); string Month = pc.GetMonth(Date).ToString(); string Day = pc.GetDayOfMonth(Date).ToString(); string Hour = pc.GetHour(Date).ToString(); string Minute = pc.GetMinute(Date).ToString(); if (Month.Length == 1) { Month = "0" + Month; } if (Day.Length == 1) { Day = "0" + Day; } if (Hour.Length == 1) { Hour = "0" + Hour; } if (Minute.Length == 1) { Minute = "0" + Minute; } return year + "/" + Month + "/" + Day + " " + Hour + ":" + Minute; }
public WeeklyScheduler.WeeklyTime GetDateFromPos(int x, int y) { int w = this.Width; int h = this.Height; int leftOffset = 20; int topOffset = 20; int dayWidth; int numOfDays; if (renderWeekend) { numOfDays = 7; } else { numOfDays = 5; } dayWidth = (w - leftOffset) / numOfDays; double minHeight = (double)(h - topOffset) / (24d * 60d); DateTime dt = new DateTime(0); dt = dt.AddMinutes((y - topOffset) / minHeight); DayOfWeek dow; dow = (DayOfWeek)(int)((x - leftOffset) / dayWidth + 1); WeeklyScheduler.WeeklyTime wt = new WeeklyScheduler.WeeklyTime(dow, dt.Hour, dt.Minute); return wt; }
static void SetArray() { Random r = new Random(); int year = DateTime.Now.Year; int month = DateTime.Now.Month; int day = DateTime.Now.Day; try { DateTime openTime = new DateTime(year, month, day); int openHour = 10; CultureInfo ci = CultureInfo.InvariantCulture; //Console.WriteLine(date1.ToString("hh:mm:ss", ci)); for (int i = 1; i <= 5; i++) { using (StreamWriter generate = new StreamWriter("cash" + i + ".txt")) { for (int j = openHour * 60; j <= (openHour + 8) * 60; j += 30) { generate.WriteLine( openTime.AddMinutes((double)j).ToString("HH:mm:ss", ci) + ";" + (r.Next(0, 10)).ToString() + ";"); } } } } catch (Exception e) { Console.WriteLine("Houston we have a problem: " + e.Message); } }
public static bool CalculateWin() { //int premios_restantes = Premio.GetRestantes (); int premios_restantes = int.Parse(Main.GetConfig ("cantidad_premios")); if (premios_restantes > 0) { Hashtable last_premio = Premio.GetLastByEvento (Evento.GetActivoID ()); DateTime last_date = new DateTime(); if(last_premio["id"] != null){ last_date = DateTime.Parse(last_premio["fecha_entregado"].ToString()); }else{ last_date = DateTime.Parse(GetConfig ("premios_start_date")); } DateTime end = DateTime.Parse(GetConfig ("premios_end_date")); TimeSpan duration = end - last_date; DateTime hora_proxima_entrega = last_date.AddMinutes(duration.TotalMinutes / premios_restantes); if(System.DateTime.Now > hora_proxima_entrega){ return true; } } return false; }
public static DateTime GetNextAvailability(DateTime currentAvailability, TimeSpan backoffInterval, int retryAttempts) { double backoffIntervalMinutes = backoffInterval.Minutes >= 1 ? backoffInterval.Minutes : 1; int backoffMinutes = (int)((1d / backoffIntervalMinutes) * (Math.Pow(backoffIntervalMinutes, Math.Min(retryAttempts, retryCeiling)) - 1d)); backoffMinutes = backoffMinutes >= 1 ? backoffMinutes : 1; return currentAvailability.AddMinutes(backoffMinutes); }