Skip to content
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<RepositoryUrl>git://github.com/khellang/EFCore.Sqlite.NodaTime</RepositoryUrl>
<Copyright>Copyright 2020 © Kristian Hellang, et al.</Copyright>
<Copyright>Copyright 2021 © Kristian Hellang, et al.</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand Down
15 changes: 8 additions & 7 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<Project>
<ItemGroup>
<PackageReference Update="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.5" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.6" />
<PackageReference Update="NodaTime" Version="3.0.5" />

<!-- Test -->
<PackageReference Update="Verify.Xunit" Version="8.12.5" />
<PackageReference Update="Verify.EntityFramework" Version="5.1.0" />
<PackageReference Update="Verify.Xunit" Version="11.15.1" />
<PackageReference Update="Verify.EntityFramework" Version="5.3.0" />
<PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Design" Version="5.0.1" />
<PackageReference Update="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.1" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Specification.Tests" Version="5.0.1" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Design" Version="5.0.6" />
<PackageReference Update="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.6" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Specification.Tests" Version="5.0.6" />
<PackageReference Update="coverlet.collector" Version="3.0.3" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Specification.Tests" />
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
target: 42,
sql: [
{
Type: ReaderExecuted,
Text:
SELECT CAST(((JULIANDAY('2020-10-12 17:42:16.321') - JULIANDAY("n"."LocalDateTime")) * 24) AS INTEGER)
FROM "NodaTimeTypes" AS "n"
LIMIT 2
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
target: 42,
sql: [
{
Type: ReaderExecuted,
Text:
SELECT CAST(((JULIANDAY('2020-10-10 23:42:16.363') - JULIANDAY("n"."LocalDateTime")) * 86400000) AS INTEGER)
FROM "NodaTimeTypes" AS "n"
LIMIT 2
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
target: 42,
sql: [
{
Type: ReaderExecuted,
Text:
SELECT CAST(((JULIANDAY('2020-10-11 00:24:16.321') - JULIANDAY("n"."LocalDateTime")) * 1440) AS INTEGER)
FROM "NodaTimeTypes" AS "n"
LIMIT 2
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
target: 42,
sql: [
{
Type: ReaderExecuted,
Text:
SELECT CAST(((JULIANDAY('2024-04-10 23:42:16.321') - JULIANDAY("n"."LocalDateTime")) / 30) AS INTEGER)
FROM "NodaTimeTypes" AS "n"
LIMIT 2
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
target: 42,
sql: [
{
Type: ReaderExecuted,
Text:
SELECT CAST(((JULIANDAY('2020-10-10 23:42:58.321') - JULIANDAY("n"."LocalDateTime")) * 86400) AS INTEGER)
FROM "NodaTimeTypes" AS "n"
LIMIT 2
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
target: 42,
sql: [
{
Type: ReaderExecuted,
Text:
SELECT CAST(((JULIANDAY('2021-07-31 23:42:16.321') - JULIANDAY("n"."LocalDateTime")) / 7) AS INTEGER)
FROM "NodaTimeTypes" AS "n"
LIMIT 2
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
target: 42,
sql: [
{
Type: ReaderExecuted,
Text:
SELECT CAST(((JULIANDAY('2062-10-10 23:42:16.321') - JULIANDAY("n"."LocalDateTime")) / 365) AS INTEGER)
FROM "NodaTimeTypes" AS "n"
LIMIT 2
}
]
}
41 changes: 41 additions & 0 deletions EFCore.Sqlite.NodaTime.Tests/LocalDateTimeDateDiffQueryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Threading.Tasks;
using NodaTime;
using Xunit;

namespace Microsoft.EntityFrameworkCore.Sqlite
{
public class LocalDateTimeDateDiffQueryTests : MethodQueryTests<LocalDateTime>
{
public LocalDateTimeDateDiffQueryTests() : base(x => x.LocalDateTime)
{
}

[Fact]
public Task DateDiffYear() => VerifyMethod(x => EF.Functions
.DateDiffYear(x, LocalDateTimeQueryTests.Value.PlusYears(42)));

[Fact]
public Task DateDiffMonth() => VerifyMethod(x => EF.Functions
.DateDiffMonth(x, LocalDateTimeQueryTests.Value.PlusMonths(42)));

[Fact]
public Task DateDiffWeek() => VerifyMethod(x => EF.Functions
.DateDiffWeek(x, LocalDateTimeQueryTests.Value.PlusWeeks(42)));

[Fact]
public Task DateDiffHour() => VerifyMethod(x => EF.Functions
.DateDiffHour(x, LocalDateTimeQueryTests.Value.PlusHours(42)));

[Fact]
public Task DateDiffMinute() => VerifyMethod(x => EF.Functions
.DateDiffMinute(x, LocalDateTimeQueryTests.Value.PlusMinutes(42)));

[Fact]
public Task DateDiffSecond() => VerifyMethod(x => EF.Functions
.DateDiffSecond(x, LocalDateTimeQueryTests.Value.PlusSeconds(42)));

[Fact]
public Task DateDiffMillisecond() => VerifyMethod(x => EF.Functions
.DateDiffMillisecond(x, LocalDateTimeQueryTests.Value.PlusMilliseconds(42)));
}
}
2 changes: 1 addition & 1 deletion EFCore.Sqlite.NodaTime.Tests/MethodQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected MethodQueryTests(Expression<Func<NodaTimeTypes, T>> selector) : base(s
{
}

protected Task VerifyMethod(Expression<Func<T, T>> selector, [CallerFilePath] string sourceFile = "")
protected Task VerifyMethod<TResult>(Expression<Func<T, TResult>> selector, [CallerFilePath] string sourceFile = "")
{
SqlRecording.StartRecording();
var value = Query.Select(selector).Single();
Expand Down
2 changes: 1 addition & 1 deletion EFCore.Sqlite.NodaTime/EFCore.Sqlite.NodaTime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AssemblyName>EntityFrameworkCore.Sqlite.NodaTime</AssemblyName>
<PackageId>EntityFrameworkCore.Sqlite.NodaTime</PackageId>
<TargetFramework>netstandard2.1</TargetFramework>
<VersionPrefix>5.0.2</VersionPrefix>
<VersionPrefix>5.1.0</VersionPrefix>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Diagnostics;
using NodaTime;

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
[ExcludeFromCodeCoverage]
public static class SqliteNodaTimeDbFunctionsExtensions
{
public static int DateDiffYear(this DbFunctions _, LocalDate startDate, LocalDate endDate)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffYear)));

public static int? DateDiffYear(this DbFunctions _, LocalDate? startDate, LocalDate? endDate)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffYear)));

public static int DateDiffYear(this DbFunctions _, LocalDateTime startDateTime, LocalDateTime endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffYear)));

public static int? DateDiffYear(this DbFunctions _, LocalDateTime? startDateTime, LocalDateTime? endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffYear)));

public static int DateDiffMonth(this DbFunctions _, LocalDate startDate, LocalDate endDate)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMonth)));

public static int? DateDiffMonth(this DbFunctions _, LocalDate? startDate, LocalDate? endDate)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMonth)));

public static int DateDiffMonth(this DbFunctions _, LocalDateTime startDateTime, LocalDateTime endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMonth)));

public static int? DateDiffMonth(this DbFunctions _, LocalDateTime? startDateTime, LocalDateTime? endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMonth)));

public static int DateDiffWeek(this DbFunctions _, LocalDate startDate, LocalDate endDate)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffWeek)));

public static int? DateDiffWeek(this DbFunctions _, LocalDate? startDate, LocalDate? endDate)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffWeek)));

public static int DateDiffWeek(this DbFunctions _, LocalDateTime startDateTime, LocalDateTime endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffWeek)));

public static int? DateDiffWeek(this DbFunctions _, LocalDateTime? startDateTime, LocalDateTime? endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffWeek)));

public static int DateDiffDay(this DbFunctions _, LocalDate startDate, LocalDate endDate)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffDay)));

public static int? DateDiffDay(this DbFunctions _, LocalDate? startDate, LocalDate? endDate)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffDay)));

public static int DateDiffDay(this DbFunctions _, LocalDateTime startDateTime, LocalDateTime endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffDay)));

public static int? DateDiffDay(this DbFunctions _, LocalDateTime? startDateTime, LocalDateTime? endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffDay)));

public static int DateDiffHour(this DbFunctions _, LocalDateTime startDateTime, LocalDate endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffHour)));

public static int? DateDiffHour(this DbFunctions _, LocalDateTime? startDateTime, LocalDateTime? endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffHour)));

public static int DateDiffHour(this DbFunctions _, LocalTime startTime, LocalTime endTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffHour)));

public static int? DateDiffHour(this DbFunctions _, LocalTime? startTime, LocalTime? endTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffHour)));

public static int DateDiffMinute(this DbFunctions _, LocalDateTime startDateTime, LocalDateTime endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMinute)));

public static int? DateDiffMinute(this DbFunctions _, LocalDateTime? startDateTime, LocalDateTime? endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMinute)));

public static int DateDiffMinute(this DbFunctions _, LocalTime startTime, LocalTime endTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMinute)));

public static int? DateDiffMinute(this DbFunctions _, LocalTime? startTime, LocalTime? endTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMinute)));

public static int DateDiffSecond(this DbFunctions _, LocalDateTime startDateTime, LocalDateTime endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffSecond)));

public static int? DateDiffSecond(this DbFunctions _, LocalDateTime? startDateTime, LocalDateTime? endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffSecond)));

public static int DateDiffSecond(this DbFunctions _, LocalTime startTime, LocalTime endTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffSecond)));

public static int? DateDiffSecond(this DbFunctions _, LocalTime? startTime, LocalTime? endTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffSecond)));

public static int DateDiffMillisecond(this DbFunctions _, LocalDateTime startDateTime, LocalDateTime endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMillisecond)));

public static int? DateDiffMillisecond(this DbFunctions _, LocalDateTime? startDateTime, LocalDateTime? endDateTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMillisecond)));

public static int DateDiffMillisecond(this DbFunctions _, LocalTime startTime, LocalTime endTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMillisecond)));

public static int? DateDiffMillisecond(this DbFunctions _, LocalTime? startTime, LocalTime? endTime)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DateDiffMillisecond)));
}
}
3 changes: 3 additions & 0 deletions EFCore.Sqlite.NodaTime/Extensions/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ internal static SqlExpression Strftime(this ISqlExpressionFactory factory, Type
return result;
}

internal static SqlExpression JulianDay(this ISqlExpressionFactory factory, SqlExpression argument, Type returnType)
=> factory.DateFunction("JULIANDAY", ImmutableList<SqlExpression>.Empty.Add(argument), returnType);

private static SqlExpression DateFunction(this ISqlExpressionFactory factory, string name, IImmutableList<SqlExpression> arguments, Type returnType)
=> factory.Function(name, arguments, nullable: true, arguments.Select(_ => true), returnType);

Expand Down
Loading