Dates and Times
Assertions are available for TimeSpan, DateTimeOffset and DateOnly via .Should(). All of them support the comparisons from ComparableAssertions<TSelf, T> and equality from ObjectAssertions<TSelf, T>:
var value = TimeSpan.FromSeconds(5);
value.Should().Equal(TimeSpan.FromMilliseconds(5000));
value.Should().NotEqual(TimeSpan.FromSeconds(10));
value.Should().BeLessThan(TimeSpan.FromSeconds(10));
value.Should().BeLessThanOrEqualTo(TimeSpan.FromSeconds(5));
value.Should().BeGreaterThan(TimeSpan.FromSeconds(1));
value.Should().BeGreaterThanOrEqualTo(TimeSpan.FromSeconds(5));
value.Should().BeInRange(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10)); // Inclusive.Chainable methods return an AssertionsChain<TAssertions, T>.
Values are shown in assertion messages in a culture-invariant format: TimeSpan uses the constant format, for example 01:30:00, DateTimeOffset uses ISO 8601, for example 2026-09-30T12:00:00+01:00, and DateOnly uses yyyy-MM-dd, for example 2026-09-30.
TimeSpan
TimeSpanAssertions extends NumericAssertions<TSelf, T>, so it has the sign and zero assertions too. As with numbers, TimeSpan.Zero is neither positive nor negative:
TimeSpan.FromSeconds(5).Should().BePositive();
TimeSpan.FromSeconds(-5).Should().BeNegative();
TimeSpan.Zero.Should().BeZero();
TimeSpan.FromSeconds(1).Should().NotBeZero();When asserting on measured durations, such as elapsed times from a Stopwatch, use BeApproximately with a precision that defines the allowed tolerance either side of the expected value:
var elapsed = stopwatch.Elapsed;
elapsed.Should().BeApproximately(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(100));
elapsed.Should().NotBeApproximately(TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(100));DateTimeOffset
DateTimeOffsetAssertions adds BeBefore, BeOnOrBefore, BeAfter and BeOnOrAfter, which read more naturally than the comparison methods:
var value = new DateTimeOffset(2026, 9, 30, 12, 0, 0, TimeSpan.Zero);
value.Should().BeAfter(value.AddDays(-1));
value.Should().BeOnOrBefore(value);Use BeApproximately to check a value is close to an expected value, for example a timestamp that should be about now:
order.CreatedAt.Should().BeApproximately(DateTimeOffset.UtcNow, TimeSpan.FromSeconds(5));Like DateTimeOffset.Equals, equality and comparisons are based on the point in time and ignore the offset, so 12:00 +00:00 equals 13:00 +01:00. Use BeExactly to compare the offset too, or HaveOffset to check just the offset:
var utc = new DateTimeOffset(2026, 9, 30, 12, 0, 0, TimeSpan.Zero);
var plusOne = new DateTimeOffset(2026, 9, 30, 13, 0, 0, TimeSpan.FromHours(1));
utc.Should().Equal(plusOne); // Passes - same point in time.
utc.Should().BeExactly(plusOne); // Fails - different offsets.
plusOne.Should().HaveOffset(TimeSpan.FromHours(1));DateOnly
DateOnlyAssertions has the same BeBefore, BeOnOrBefore, BeAfter and BeOnOrAfter assertions, plus BeOnDayOfWeek:
var date = new DateOnly(2026, 9, 30);
date.Should().BeAfter(new DateOnly(2026, 1, 1)).And.BeOnDayOfWeek(DayOfWeek.Wednesday);