Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DateTime.Now as default value. Add UniversalTimeConverter. #76

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<EnablePackageVersionOverride>true</EnablePackageVersionOverride>
<MicrosoftPackageVersion6>6.0.29</MicrosoftPackageVersion6>
<MicrosoftPackageVersion7>7.0.18</MicrosoftPackageVersion7>
<MicrosoftPackageVersion8>8.0.4</MicrosoftPackageVersion8>
<GrpcAspNetCoreVersion>2.62.0</GrpcAspNetCoreVersion>
<QuartzVersion>3.8.1</QuartzVersion>
<MicrosoftPackageVersion6>6.0.31</MicrosoftPackageVersion6>
<MicrosoftPackageVersion7>7.0.20</MicrosoftPackageVersion7>
<MicrosoftPackageVersion8>8.0.6</MicrosoftPackageVersion8>
<GrpcAspNetCoreVersion>2.63.0</GrpcAspNetCoreVersion>
<QuartzVersion>3.9.0</QuartzVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Apache.NMS.ActiveMQ" Version="2.1.0" />
<PackageVersion Include="Autofac" Version="8.0.0" />
<PackageVersion Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" />
<PackageVersion Include="Autofac.Extras.DynamicProxy" Version="7.1.0" />
<PackageVersion Include="AutoMapper" Version="13.0.1" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.20.0" />
<PackageVersion Include="Castle.Core" Version="5.1.1" />
<PackageVersion Include="Consul" Version="1.6.10.9" />
<PackageVersion Include="FluentValidation" Version="11.9.0" />
<PackageVersion Include="FluentValidation" Version="11.9.1" />
<PackageVersion Include="IdentityModel" Version="7.0.0" />
<PackageVersion Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="6.2.0" />
<PackageVersion Include="Mapster" Version="7.4.0" />
<PackageVersion Include="Mapster.DependencyInjection" Version="1.0.1" />
<PackageVersion Include="MediatR" Version="12.1.1" />
<PackageVersion Include="MediatR.Contracts" Version="2.0.1" />
<PackageVersion Include="mongocsharpdriver" Version="2.24.0" />
<PackageVersion Include="mongocsharpdriver" Version="2.25.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Polly" Version="8.3.1" />
<PackageVersion Include="Polly" Version="8.4.0" />
<PackageVersion Include="protobuf-net" Version="3.1.33" />
<PackageVersion Include="Quartz" Version="$(QuartzVersion)" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="$(QuartzVersion)" />
Expand All @@ -35,20 +35,20 @@
<PackageVersion Include="Refit" Version="6.3.2" />
<PackageVersion Include="Refit.HttpClientFactory" Version="6.3.2" />
<PackageVersion Include="Refit.Newtonsoft.Json" Version="6.3.2" />
<PackageVersion Include="Serilog" Version="3.1.1" />
<PackageVersion Include="Serilog" Version="4.0.0" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageVersion Include="Serilog.Enrichers.Environment" Version="2.3.0" />
<PackageVersion Include="Serilog.Sinks.Elasticsearch" Version="10.0.0" />
<PackageVersion Include="Serilog.Sinks.Email" Version="3.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.7.33" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="System.Interactive" Version="6.0.1" />
<PackageVersion Include="System.Diagnostics.PerformanceCounter" Version="8.0.0" />
<PackageVersion Include="System.Reactive" Version="6.0.0" />
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<PackageVersion Include="System.Runtime.Caching" Version="8.0.0" />
<PackageVersion Include="System.Runtime.Loader" Version="4.3.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.3" />
Expand Down Expand Up @@ -112,7 +112,7 @@
<!-- Grpc -->
<ItemGroup>
<PackageVersion Include="Google.Api.CommonProtos" Version="2.12.0" />
<PackageVersion Include="Google.Protobuf" Version="3.26.1" />
<PackageVersion Include="Google.Protobuf" Version="3.27.0" />
<PackageVersion Include="Grpc" Version="2.46.6" />
<PackageVersion Include="Grpc.AspNetCore" Version="$(GrpcAspNetCoreVersion)" />
<PackageVersion Include="Grpc.AspNetCore.HealthChecks" Version="$(GrpcAspNetCoreVersion)" />
Expand All @@ -126,17 +126,17 @@
<!-- Tests -->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="xunit" Version="2.7.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="xunit" Version="2.8.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Xunit.DependencyInjection" Version="9.1.0" />
<PackageVersion Include="Xunit.DependencyInjection" Version="9.3.0" />
<PackageVersion Include="Xunit.DependencyInjection.Logging" Version="9.0.0" />
<PackageVersion Include="Moq" Version="4.20.70" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Source/Euonia.Repository.EfCore/DataContextBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected virtual void SetEntryValues(IEnumerable<EntityEntry> 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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace Nerosoft.Euonia.Repository.EfCore;

/// <summary>
/// Defines conversion for <see cref="DateTime"/> values to universal time.
/// </summary>
public class UniversalTimeConverter : ValueConverter<DateTime, DateTime>
{
/// <summary>
/// Initializes a new instance of the <see cref="UniversalTimeConverter"/> class.
/// </summary>
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
};
}
}
2 changes: 1 addition & 1 deletion project.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>8.1.24</Version>
<Version>8.1.25</Version>
<Authors>damon</Authors>
<Company>Nerosoft Ltd.</Company>
<Product>Euonia</Product>
Expand Down
Loading