Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
572 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#if NET6_0_OR_GREATER | ||
|
||
using System; | ||
|
||
namespace FluentAssertions.Common; | ||
|
||
internal static class TimeOnlyExtensions | ||
{ | ||
/// <summary> | ||
/// Determines if <paramref name="subject"/> is close to <paramref name="other"/> within a given <paramref name="precision"/>. | ||
/// </summary> | ||
/// <param name="subject">The time to check</param> | ||
/// <param name="other">The time to be close to</param> | ||
/// <param name="precision">The precision that <paramref name="other"/> may differ from <paramref name="subject"/></param> | ||
/// <remarks> | ||
/// <see cref="TimeOnly.IsBetween(TimeOnly, TimeOnly)" /> checks the right-open interval, whereas this method checks the closed interval. | ||
/// </remarks> | ||
public static bool IsCloseTo(this TimeOnly subject, TimeOnly other, TimeSpan precision) | ||
{ | ||
long startTicks = other.Add(-precision).Ticks; | ||
long endTicks = other.Add(precision).Ticks; | ||
long ticks = subject.Ticks; | ||
|
||
return startTicks <= endTicks | ||
? (startTicks <= ticks && endTicks >= ticks) | ||
: (startTicks <= ticks || endTicks >= ticks); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.