Skip to content

Commit

Permalink
Restore DateOnly and TimeOnly helpers for .NET 8 (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcominerva authored Mar 26, 2024
2 parents 3fc80b7 + 1ab9d34 commit 4e73684
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.5" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions samples/TinyHelpers.EntityFrameworkCore.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
{
Title = "TinyHelpers",
Content = "A collection of helper methods and classes that I use every day. I have packed them in a single library to avoid code duplication.",
Authors = new string[] { "Marco", "Bot" },
Authors = ["Marco", "Bot"],
Date = DateOnly.FromDateTime(DateTime.UtcNow.AddDays(-1)),
Reviews = new List<Review>
{
Reviews =
[
new() { User = "Pippo", Score = 5, Time = TimeOnly.FromDateTime(DateTime.Now) },
new() { User = "Pluto", Score = 4 }
}
]
};

dataContext.Posts.Add(post);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/TinyHelpers.Dapper/TinyHelpers.Dapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.28" />
<PackageReference Include="TinyHelpers" Version="3.1.2" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="TinyHelpers" Version="3.1.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace TinyHelpers.EntityFrameworkCore.Comparers;

#if NET6_0 || NET7_0
public class DateOnlyComparer : ValueComparer<DateOnly>
{
public DateOnlyComparer() : base(
(d1, d2) => d1.DayNumber == d2.DayNumber,
d => d.GetHashCode())
{
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace TinyHelpers.EntityFrameworkCore.Comparers;

#if NET6_0 || NET7_0
public class TimeOnlyComparer : ValueComparer<TimeOnly>
{
public TimeOnlyComparer() : base(
(t1, t2) => t1.Ticks == t2.Ticks,
t => t.GetHashCode())
{
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace TinyHelpers.EntityFrameworkCore.Converters;

#if NET6_0 || NET7_0
public class DateOnlyConverter : ValueConverter<DateOnly, DateTime>
{
public DateOnlyConverter() : base(
dateOnly => dateOnly.ToDateTime(TimeOnly.MinValue),
dateTime => DateOnly.FromDateTime(dateTime))
{
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace TinyHelpers.EntityFrameworkCore.Converters;

#if NET6_0 || NET7_0
public class TimeOnlyConverter : ValueConverter<TimeOnly, TimeSpan>
{
public TimeOnlyConverter() : base(
timeOnly => timeOnly.ToTimeSpan(),
timeSpan => TimeOnly.FromTimeSpan(timeSpan))
{
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ namespace TinyHelpers.EntityFrameworkCore.Extensions;

public static class PropertyBuilderExtensions
{
#if NET6_0 || NET7_0
public static PropertyBuilder<DateOnly> HasDateOnlyConversion<DateOnly>(this PropertyBuilder<DateOnly> propertyBuilder)
=> propertyBuilder.HasConversion<DateOnlyConverter, DateOnlyComparer>();

public static PropertyBuilder<TimeOnly> HasTimeOnlyConversion<TimeOnly>(this PropertyBuilder<TimeOnly> propertyBuilder)
=> propertyBuilder.HasConversion<TimeOnlyConverter, TimeOnlyComparer>();
#endif

public static PropertyBuilder<T?> HasJsonConversion<T>(this PropertyBuilder<T?> propertyBuilder, JsonSerializerOptions? jsonSerializerOptions = null, bool useUtcDate = false, bool serializeEnumAsString = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="TinyHelpers" Version="3.1.2" />
<PackageReference Include="TinyHelpers" Version="3.1.3" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.27" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.28" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.17" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/TinyHelpers.Tests/TinyHelpers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit 4e73684

Please sign in to comment.