1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -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

@ -159,6 +159,20 @@ public class DatabaseContext : DbContext
// Make sure this is called after configuring all the entities as it iterates through all setup entities.
private void ConfigureDateTimeUtcQueries(ModelBuilder builder)
{
ValueConverter<DateTime, DateTime> converter;
if (Database.IsNpgsql())
{
converter = new ValueConverter<DateTime, DateTime>(
v => v,
d => new DateTimeOffset(d).UtcDateTime);
}
else
{
converter = new ValueConverter<DateTime, DateTime>(
v => v,
v => new DateTime(v.Ticks, DateTimeKind.Utc));
}
foreach (var entityType in builder.Model.GetEntityTypes())
{
if (entityType.IsKeyless)
@ -169,10 +183,7 @@ public class DatabaseContext : DbContext
{
if (property.ClrType == typeof(DateTime) || property.ClrType == typeof(DateTime?))
{
property.SetValueConverter(
new ValueConverter<DateTime, DateTime>(
v => v,
v => new DateTime(v.Ticks, DateTimeKind.Utc)));
property.SetValueConverter(converter);
}
}
}