diff --git a/Directory.Packages.props b/Directory.Packages.props index 952f7d0..3b823a7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,11 +2,11 @@ true true - 6.0.29 - 7.0.18 - 8.0.4 - 2.62.0 - 3.8.1 + 6.0.31 + 7.0.20 + 8.0.6 + 2.63.0 + 3.9.0 @@ -14,19 +14,19 @@ - + - + - + - + @@ -35,20 +35,20 @@ - + - + - + @@ -112,7 +112,7 @@ - + @@ -126,9 +126,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -136,7 +136,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Source/Euonia.Repository.EfCore/DataContextBase.cs b/Source/Euonia.Repository.EfCore/DataContextBase.cs index e6aa531..bfb3db0 100644 --- a/Source/Euonia.Repository.EfCore/DataContextBase.cs +++ b/Source/Euonia.Repository.EfCore/DataContextBase.cs @@ -109,7 +109,7 @@ protected virtual void SetEntryValues(IEnumerable entries) foreach (var entry in entries) { - var time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Unspecified); + var time = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified); switch (entry.State) { diff --git a/Source/Euonia.Repository.EfCore/ValueConversion/UniversalTimeConverter.cs b/Source/Euonia.Repository.EfCore/ValueConversion/UniversalTimeConverter.cs new file mode 100644 index 0000000..f2ac0e4 --- /dev/null +++ b/Source/Euonia.Repository.EfCore/ValueConversion/UniversalTimeConverter.cs @@ -0,0 +1,39 @@ +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Nerosoft.Euonia.Repository.EfCore; + +/// +/// Defines conversion for values to universal time. +/// +public class UniversalTimeConverter : ValueConverter +{ + /// + /// Initializes a new instance of the class. + /// + public UniversalTimeConverter() + : base(t => ConvertToUniversalTime(t), t => ConvertToLocalTime(t)) + { + } + + private static DateTime ConvertToUniversalTime(DateTime time) + { + return time.Kind switch + { + DateTimeKind.Unspecified => DateTime.SpecifyKind(time, DateTimeKind.Local).ToUniversalTime(), + DateTimeKind.Local => time.ToUniversalTime(), + DateTimeKind.Utc => time, + _ => time + }; + } + + private static DateTime ConvertToLocalTime(DateTime time) + { + return time.Kind switch + { + DateTimeKind.Unspecified => DateTime.SpecifyKind(time, DateTimeKind.Utc).ToLocalTime(), + DateTimeKind.Utc => time.ToLocalTime(), + DateTimeKind.Local => time, + _ => time + }; + } +} diff --git a/project.props b/project.props index 2180d69..8840538 100644 --- a/project.props +++ b/project.props @@ -1,6 +1,6 @@ - 8.1.24 + 8.1.25 damon Nerosoft Ltd. Euonia