public void PlusMinutes_Simple() { LocalDateTime start = new LocalDateTime(2011, 4, 2, 12, 15, 8); LocalDateTime expectedForward = new LocalDateTime(2011, 4, 2, 12, 17, 8); LocalDateTime expectedBackward = new LocalDateTime(2011, 4, 2, 12, 13, 8); Assert.AreEqual(expectedForward, start.PlusMinutes(2)); Assert.AreEqual(expectedBackward, start.PlusMinutes(-2)); }
public void InPeriod() { Assert.IsFalse(_tick.InPeriod(null)); Assert.IsFalse(_tick.InPeriod(_beginTime.PlusDays(-1))); Assert.IsFalse(_tick.InPeriod(_beginTime.PlusDays(1))); Assert.IsTrue(_tick.InPeriod(_beginTime.PlusMinutes(30))); Assert.IsFalse(_tick.InPeriod(_beginTime.PlusMinutes(90))); Assert.IsTrue(_tick.InPeriod(_beginTime)); Assert.IsFalse(_tick.InPeriod(_endTime)); }
public static LocalDateTime ToNearestHour(this LocalDateTime dateTime, RoundingDirection direction) { if (dateTime.Minute == 0) { return(dateTime); } return(direction == RoundingDirection.Up ? dateTime.PlusMinutes(60 - dateTime.Minute) : dateTime.PlusMinutes(-dateTime.Minute)); }
public void Addition_Duration() { const int minutes = 23; const int hours = 3; const int milliseconds = 40000; const long seconds = 321; const long nanoseconds = 12345; const long ticks = 5432112345; // Test all three approaches... not bothering to check a different calendar, // but we'll use two different offsets. OffsetDateTime start = new LocalDateTime(2014, 08, 14, 6, 51).WithOffset(Offset.FromHours(1)); Duration duration = Duration.FromHours(8) + Duration.FromMinutes(9); OffsetDateTime expected = new LocalDateTime(2014, 08, 14, 15, 0).WithOffset(Offset.FromHours(1)); Assert.AreEqual(expected, start + duration); Assert.AreEqual(expected, start.Plus(duration)); Assert.AreEqual(expected, OffsetDateTime.Add(start, duration)); Assert.AreEqual(start + Duration.FromHours(hours), start.PlusHours(hours)); Assert.AreEqual(start + Duration.FromHours(-hours), start.PlusHours(-hours)); Assert.AreEqual(start + Duration.FromMinutes(minutes), start.PlusMinutes(minutes)); Assert.AreEqual(start + Duration.FromMinutes(-minutes), start.PlusMinutes(-minutes)); Assert.AreEqual(start + Duration.FromSeconds(seconds), start.PlusSeconds(seconds)); Assert.AreEqual(start + Duration.FromSeconds(-seconds), start.PlusSeconds(-seconds)); Assert.AreEqual(start + Duration.FromMilliseconds(milliseconds), start.PlusMilliseconds(milliseconds)); Assert.AreEqual(start + Duration.FromMilliseconds(-milliseconds), start.PlusMilliseconds(-milliseconds)); Assert.AreEqual(start + Duration.FromTicks(ticks), start.PlusTicks(ticks)); Assert.AreEqual(start + Duration.FromTicks(-ticks), start.PlusTicks(-ticks)); Assert.AreEqual(start + Duration.FromNanoseconds(nanoseconds), start.PlusNanoseconds(nanoseconds)); Assert.AreEqual(start + Duration.FromNanoseconds(-nanoseconds), start.PlusNanoseconds(-nanoseconds)); }
public void SplitByHour() { var time = new LocalDateTime(1970, 1, 1, 10, 0, 0); TimeSeries series = GenerateTimeSeries.From(time, time.PlusMinutes(1), time.PlusMinutes(2), time.PlusMinutes(10), time.PlusMinutes(15), time.PlusMinutes(25), time.PlusHours(1), time.PlusHours(5), time.PlusHours(10).PlusMinutes(10), time.PlusHours(10).PlusMinutes(20), time.PlusHours(10).PlusMinutes(30)); var subseries = series.Split(Period.FromHours(1)); Assert.Multiple(() => { Assert.AreEqual(4, subseries.Count); Assert.AreEqual(0, subseries[0].Begin); Assert.AreEqual(5, subseries[0].End); Assert.AreEqual(6, subseries[1].Begin); Assert.AreEqual(6, subseries[1].End); Assert.AreEqual(7, subseries[2].Begin); Assert.AreEqual(7, subseries[2].End); Assert.AreEqual(8, subseries[3].Begin); Assert.AreEqual(10, subseries[3].End); }); }
public void PlusMinutes() { SampleStartDateTime.PlusMinutes(3); }
public LocalDateTime PlusMinutes() => Sample.PlusMinutes(3);
public void PlusMinutes() { Sample.PlusMinutes(3).Consume(); }
public LocalDateTime PlusMinutes() { return(Sample.PlusMinutes(3)); }
private string getUrlEncodedTime(LocalDateTime baseTime, int minutes) => WebUtility.UrlEncode(baseTime.PlusMinutes(minutes).ToString("s", CultureInfo.InvariantCulture));
public static LocalDateTime[] pretty_second(LocalDateTime min, LocalDateTime max, ulong diff, int n) { var length = 60; { var minfit = double.MaxValue; foreach (var l in length_secondes) { var fit = Abs((double)diff - l * n); if (fit < minfit) { length = l; minfit = fit; } } } var start = min; { var lower = min.With(TimeAdjusters.TruncateToMinute); var minfit = double.MaxValue; var current = lower; while (current <= min) { var fit = _diff(min, current); if (fit < minfit) { start = current; minfit = fit; } current = current.PlusSeconds(length); } } var end = max; { var lower = max.With(TimeAdjusters.TruncateToMinute); var upper = max.PlusMinutes(1).With(TimeAdjusters.TruncateToMinute); var minfit = double.MaxValue; var current = lower; while (current <= upper) { if (current >= max) { var fit = _diff(max, current); if (fit < minfit) { end = current; minfit = fit; } } current = current.PlusSeconds(length); } } var period = end - start; var results = new LocalDateTime[(int)((period.Minutes * 60 + period.Seconds) / (double)length + 1)]; { var i = 0; var current = start; while (current <= end) { results[i++] = current; current = current.PlusSeconds(length); } } return(results); }
/// <summary> /// Add minutes /// </summary> /// <param name="lt"></param> /// <param name="minutes"></param> /// <returns></returns> public static LocalDateTime AddMinutes(this LocalDateTime lt, long minutes) => lt.PlusMinutes(minutes);