-
Notifications
You must be signed in to change notification settings - Fork 53
DateTimeOffset checks
DateTimeOffset specific checks were added in V 2.6.0
Checks that the sut is equal to the expected DateTimeOffset, disregarding milliseconds. Note that the TimeSpan needs to be equal to the expected one. If you need to check the aggregated DateTime, consider using MatchTheSameUtcInstant.
var sut = new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 12, 152), TimeSpan.Zero);
// This check succeeds
Check.That(sut).IsEqualToIgnoringMilliseconds(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 12, 870), TimeSpan.Zero);
// This check fails
Check.That(sut).IsEqualToIgnoringMilliseconds(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 13, 152), TimeSpan.Zero);
Checks that the sut is equal to the expected DateTime, disregarding seconds.
var sut = new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 12, 152), TimeSpan.Zero);
// This check succeeds
Check.That(sut).IsEqualToIgnoringSeconds(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 12, 870), TimeSpan.Zero);
// This check fails
Check.That(sut).IsEqualToIgnoringSeconds(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 13, 152), TimeSpan.Zero);
Checks that the sut is equal to the expected DateTimeOffset, disregarding minutes.
var sut = new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 12, 152), TimeSpan.Zero);
// This check succeeds
Check.That(sut).IsEqualToIgnoringMinutes(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 12, 870), TimeSpan.Zero);
// This check fails
Check.That(sut).IsEqualToIgnoringMinutes(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 13, 152), TimeSpan.Zero);
Checks that the sut is equal to the expected DateTimeOffset, disregarding minutes.
var sut = new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 12, 152), TimeSpan.Zero);
// This check succeeds
Check.That(sut).IsEqualToIgnoringHours(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 12, 870), TimeSpan.Zero);
// This check fails
Check.That(sut).IsEqualToIgnoringHours(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 13, 152), TimeSpan.Zero);
Checks that the sut represents the expected Utc date time.
// successful checks
DateTimeOffset dateTimeOffset1 = new DateTimeOffset(new DateTime(2000, 1, 1, 0, 0, 1, 0), TimeSpan.Zero);
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2000, 1, 1, 1, 0, 1, 0), TimeSpan.FromHours(1));
Check.That(dateTimeOffset1).MatchTheSameUtcInstant(dateTimeOffset2);
// failing checks (even if time difference is only 1ms)
DateTimeOffset dateTimeOffsetA = new DateTimeOffset(new DateTime(2000, 1, 1, 0, 0, 1, 0), TimeSpan.Zero);
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2000, 1, 1, 1, 0, 1, 999), TimeSpan.FromHours(1));
Check.That(dateTimeOffsetA).MatchTheSameUtcInstant(dateTimeOffsetB);
Checks that the sut represents the expected Utc date time disregarding the milliseconds.
// successful checks
DateTimeOffset dateTimeOffset1 = new DateTimeOffset(new DateTime(2000, 1, 1, 0, 0, 1, 0), TimeSpan.Zero);
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2000, 1, 1, 1, 0, 1, 100), TimeSpan.FromHours(1));
Check.That(dateTimeOffset1).MatchTheSameUtcInstantIgnoringMillis(dateTimeOffset2);
// failing checks (even if time difference is only 1ms)
DateTimeOffset dateTimeOffsetA = new DateTimeOffset(new DateTime(2000, 1, 1, 0, 0, 1, 0), TimeSpan.Zero);
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2000, 1, 1, 1, 0, 0, 999), TimeSpan.FromHours(1));
Check.That(dateTimeOffsetA).MatchTheSameUtcInstantIgnoringMillis(dateTimeOffsetB);
Checks that the sut represents the expected Utc date time disregarding the seconds.
// successful checks
DateTimeOffset dateTimeOffset1 = new DateTimeOffset(new DateTime(2000, 1, 1, 0, 0, 1, 0), TimeSpan.Zero);
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2000, 1, 1, 1, 0, 9, 0), TimeSpan.FromHours(1));
Check.That(dateTimeOffset1).MatchTheSameUtcInstantIgnoringSeconds(dateTimeOffset2);
// failing checks (even if time difference is only 1ms)
DateTimeOffset dateTimeOffsetA = new DateTimeOffset(new DateTime(2000, 1, 1, 0, 0, 1, 0), TimeSpan.Zero);
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2000, 1, 1, 1, 1, 0, 999), TimeSpan.FromHours(1));
Check.That(dateTimeOffsetA).MatchTheSameUtcInstantIgnoringSeconds(dateTimeOffsetB);
Checks that the sut represents the expected Utc date time disregarding the minutes.
// successful checks
DateTimeOffset dateTimeOffset1 = new DateTimeOffset(new DateTime(2000, 1, 1, 0, 5, 1, 0), TimeSpan.Zero);
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2000, 1, 1, 1, 1, 9, 0), TimeSpan.FromHours(1));
Check.That(dateTimeOffset1).MatchTheSameUtcInstantIgnoringMinutes(dateTimeOffset2);
// failing checks (even if time difference is only 1ms)
DateTimeOffset dateTimeOffsetA = new DateTimeOffset(new DateTime(2000, 1, 1, 0, 0, 1, 0), TimeSpan.Zero);
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2000, 1, 1, 2, 1, 0, 999), TimeSpan.FromHours(1));
Check.That(dateTimeOffsetA).MatchTheSameUtcInstantIgnoringMinutes(dateTimeOffsetB);
Checks that the sut represents the expected Utc date time disregarding the hours.
// successful checks
DateTimeOffset dateTimeOffset1 = new DateTimeOffset(new DateTime(2000, 1, 1, 2, 0, 1, 0), TimeSpan.Zero);
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2000, 1, 1, 1, 1, 9, 0), TimeSpan.FromHours(1));
Check.That(dateTimeOffset1).MatchTheSameUtcInstantIgnoringHours(dateTimeOffset2);
// failing checks (even if time difference is only 1ms)
DateTimeOffset dateTimeOffsetA = new DateTimeOffset(new DateTime(2000, 1, 1, 0, 0, 1, 0), TimeSpan.Zero);
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2000, 1, 2, 2, 1, 0, 999), TimeSpan.FromHours(1));
Check.That(dateTimeOffsetA).MatchTheSameUtcInstantIgnoringHours(dateTimeOffsetB);
Checks that sut is close to the expected date time, within +/- tolerance. The tolerance can be a Timespan or a Duration.
var sut = new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 12), TimeSpan.Zero);
// This check succeeds
Check.That(sut).IsCloseTo(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 15), TimeSpan.Zero), new Duration(5, TimeUnit.Minutes));
// This check succeeds
Check.That(sut).IsCloseTo(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 15), TimeSpan.Zero), TimeSpan.FromMinutes(5));
// This check fails
Check.That(sut).IsCloseTo(new DateTimeOffset(new DateTime(2018, 2, 6, 9, 18, 02), TimeSpan.Zero), new Duration(5, TimeUnit.Minutes));
- Welcome
- How to start
- Customising error messages
-
Check.That
- All (Equality, Type)
- Reference types
- Members based
- IEnumerable (Properties, Content, Elements)
- String (Properties, Content, RegExp )
- Numeric Type(Properties, Comparisons, Floating)
- Dictionary
- Char (Properties, Value)
- IComparable
- DateTime
- DateTimeOffset
- Misc: Boolean, TimeSpan, Stream, Enum, EventWaitHandle
- Check.ThatCode
- Check.ThatDynamic
- Extensibility
- Auxiliary types (TimeUnit)
- Mocks