1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

[PM-3581] Fix Postgres Time (#3221)

* Fix Postgres Time

- Migrate Send Tests
- Delete Old Tests

* Formatting

* Update Comment

* Change LaxComparer to Compare Some Milliseconds

* Update Comment
This commit is contained in:
Justin Baur
2024-06-28 10:13:02 -04:00
committed by GitHub
parent 48430836b6
commit 1ec2aae723
6 changed files with 115 additions and 169 deletions

View File

@ -0,0 +1,34 @@
using System.Diagnostics.CodeAnalysis;
namespace Bit.Infrastructure.IntegrationTest.Comparers;
/// <summary>
/// A datetime comparer that doesn't care about overall ticks and instead allows a configurable allowed difference.
/// </summary>
public class LaxDateTimeComparer : IEqualityComparer<DateTime>
{
public static readonly IEqualityComparer<DateTime> Default = new LaxDateTimeComparer(TimeSpan.FromMilliseconds(2));
private readonly TimeSpan _allowedDifference;
public LaxDateTimeComparer(TimeSpan allowedDifference)
{
_allowedDifference = allowedDifference;
}
public bool Equals(DateTime x, DateTime y)
{
var difference = x - y;
return difference.Duration() < _allowedDifference;
}
public int GetHashCode([DisallowNull] DateTime obj)
{
// Not used when used for Assert.Equal() overload
throw new NotImplementedException();
}
public static int RoundMilliseconds(int milliseconds)
{
return (int)Math.Round(milliseconds / 100d) * 100;
}
}