public static bool IsGreaterThan(this DateTimeOffset thisInstant, DateTimeOffset otherInstant, DateTimeRounding rounding = DateTimeRounding.Second) { return(Difference(thisInstant, otherInstant, rounding) > TimeSpan.Zero); }
public void GetValue_ValueQuarterHourRoundingStyle_NewValue(DateTime value, Rounding.RoundingStyle roundingStyle, DateTime newValue) { var rounder = new DateTimeRounding(new TimeSpan(0, 0, 15, 0), roundingStyle); Assert.That(rounder.GetValue(value), Is.EqualTo(newValue)); }
private static TimeSpan Difference(DateTimeOffset leftInstant, DateTimeOffset rightInstant, DateTimeRounding rounding = DateTimeRounding.Second) { var leftInstantUtc = leftInstant.ToUniversalTime(); var rightInstantUtc = rightInstant.ToUniversalTime(); var difference = (leftInstantUtc - rightInstantUtc); switch (rounding) { case DateTimeRounding.Second: difference = TimeSpan.FromSeconds(Math.Floor(difference.TotalSeconds)); break; } return(difference); }