public void Add_MethodEquivalents() { const int minutes = 23; const int hours = 3; const int milliseconds = 40000; const long seconds = 321; const long nanoseconds = 12345; const long ticks = 5432112345; ZonedDateTime before = SampleZone.AtStrictly(new LocalDateTime(2011, 6, 12, 15, 0)); Assert.AreEqual(before + Duration.OneDay, ZonedDateTime.Add(before, Duration.OneDay)); Assert.AreEqual(before + Duration.OneDay, before.Plus(Duration.OneDay)); Assert.AreEqual(before + Duration.FromHours(hours), before.PlusHours(hours)); Assert.AreEqual(before + Duration.FromHours(-hours), before.PlusHours(-hours)); Assert.AreEqual(before + Duration.FromMinutes(minutes), before.PlusMinutes(minutes)); Assert.AreEqual(before + Duration.FromMinutes(-minutes), before.PlusMinutes(-minutes)); Assert.AreEqual(before + Duration.FromSeconds(seconds), before.PlusSeconds(seconds)); Assert.AreEqual(before + Duration.FromSeconds(-seconds), before.PlusSeconds(-seconds)); Assert.AreEqual(before + Duration.FromMilliseconds(milliseconds), before.PlusMilliseconds(milliseconds)); Assert.AreEqual(before + Duration.FromMilliseconds(-milliseconds), before.PlusMilliseconds(-milliseconds)); Assert.AreEqual(before + Duration.FromTicks(ticks), before.PlusTicks(ticks)); Assert.AreEqual(before + Duration.FromTicks(-ticks), before.PlusTicks(-ticks)); Assert.AreEqual(before + Duration.FromNanoseconds(nanoseconds), before.PlusNanoseconds(nanoseconds)); Assert.AreEqual(before + Duration.FromNanoseconds(-nanoseconds), before.PlusNanoseconds(-nanoseconds)); }
public void PlusMinutes() { DateTimeZone dublin = DateTimeZoneProviders.Tzdb["Europe/Dublin"]; var start = Instant.FromUtc(2017, 7, 20, 5, 30); // Dublin is at UTC+1 in July 2017, so this is 6:30am. ZonedDateTime zoned = new ZonedDateTime(start, dublin); var pattern = ZonedDateTimePattern.ExtendedFormatOnlyIso; Assert.AreEqual("2017-07-20T06:31:00 Europe/Dublin (+01)", pattern.Format(Snippet.For(zoned.PlusMinutes(1)))); }
private DateTimeOffset?BackoffAndRetry(RunStatus lastRunStatus, int depth) { trace.Trace(TraceEventType.Verbose, (int)EventId.BackOffAndRetry, $"Last Run Status was: {lastRunStatus}. Backing off and retrying."); var backOffDateTime = new ZonedDateTime( new LocalDateTime(currentDate.Year, currentDate.Month, currentDate.Day, currentDate.Hour, currentDate.Minute), DateTimeZone.Utc, Offset.FromHours(0)); if (depth >= MaxDepth) { trace.Trace(TraceEventType.Verbose, (int)EventId.BackOffAndRetry, $"Current depth {depth} is equal to greater than Max depth {MaxDepth}. Using MaxBackOffInterval of {MaxBackOffInterval}"); return(new DateTimeOffset(backOffDateTime.PlusMinutes(MaxBackOffInterval).ToDateTimeUtc())); } trace.Trace(TraceEventType.Verbose, (int)EventId.BackOffAndRetry, $"Backing off for {depth * BackOffInterval}"); return(new DateTimeOffset(backOffDateTime.PlusMinutes(depth * BackOffInterval).ToDateTimeUtc())); }
public void WhenLastRunStatusError_ReturnsDepthTimes10(int depth) { var currentDate = new DateTime(2017, 06, 1, 22, 1, 0, DateTimeKind.Utc); var date = new DateCalculator(currentDate, trace) .Calculate(Frequency.Daily, 10, 1.10M, RunStatus.Error, depth); var expectedDateTime = new ZonedDateTime(new LocalDateTime(2017, 06, 1, 22, 1, 0), DateTimeZone.Utc, Offset.FromHours(0)); expectedDateTime = expectedDateTime.PlusMinutes(depth * DateCalculator.BackOffInterval); Assert.That(date.Value.UtcDateTime, Is.EqualTo(expectedDateTime.ToDateTimeUtc())); }
public async Task WriteNewScheduleTargets() { // Decisions about whether the once-daily run target is near enough: if (await WasLastRunToday()) { return; } // This will be an HHmm value such as 1030 or 2200; SchedulerQueue only invokes this // grain at 15-minute intervals, so quit unless we're near or past the run-at time. var paddedUtc = todayUtc.PlusMinutes(5); var paddedTime = paddedUtc.TimeOfDay; var runTargetUtc = await configCache.GetValue(ConstConfigKeys.ScheduleWriterRunTargetUtc); var(runHour, runMinute) = DateTimeAnalysis.GetHourMinute(runTargetUtc); if (paddedUtc.Date == todayUtc.Date && (paddedTime.Hour < runHour || (paddedTime.Hour == runHour && paddedTime.Minute < runMinute))) { return; } // Decision made: yes, write the next day's schedule records. logger.LogInformation($"WriteNewScheduleTargets"); var jobs = await scheduleRepository.GetJobsWithScheduleSettings(); if (jobs.Count == 0) { return; } foreach (var job in jobs) { try { var planner = new TargetPlanner(job, today.Plus(Duration.FromDays(1)), logger); var newSchedules = planner.GetSchedules(); if (newSchedules.Count > 0) { await InsertScheduleRows(newSchedules); } newSchedules = null; } catch { } } await configRepository.UpdateConfig(ConstConfigKeys.ScheduleWriterLastRunDateUtc, InstantPattern.General.Format(today)); }
public void RefreshTime() { // lock is set in wrapping calling code (AlgoTraderProcess.TimerCallback) lock (LockObj) { if (!AlgoTraderState.PauseSim) { if (IsSim) { if (AlgoTraderState.TradingManagerRunning) { AlgoTraderMethods.Pause(); } Time = Time.PlusMinutes(IncrementMinutes); } else { Time = UCDT.GetCurrentEastCoastTime(); } CurrentMinute = Time.Minute; } } }