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

feat: DateOnly and TimeOnly support #129

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

DeagleGross
Copy link
Collaborator

@DeagleGross DeagleGross commented Sep 21, 2024

In .NET6 DateOnly and TimeOnly were introduced. Current PR proposes support for those in Dapper.AOT.

I performed testing against MsSql and PostgreSql. Check DateOnlyTimeOnlyTests.cs for validating how data is being parsed from database via System.Data.Common.DbDataReader.

Here is how data is parsed and how I convert it:

SQL db-type c# type DbDataReader.GetValue() returns how converted notes
Postgre timestamp DateTime DateTime Convert.ToDateTime() ...
MsSql datetime DateTime DateTime Convert.ToDateTime() the only difference between Postgre and MsSql - name of "timestamp" type
Postgre timestamp DateOnly DateTime Convert.ToDateTime() -> DateOnly.FromDateTime() ...
Postgre timestamp TimeOnly DateTime Convert.ToDateTime() -> TimeOnly.FromDateTime() ...
-------
Postgre date DateTime DateTime Convert.ToDateTime() technically date is a datetime as well, so left as is
Postgre date DateOnly DateTime Convert.ToDateTime() -> DateOnly.FromDateTime()
Postgre date TimeOnly DateTime Convert.ToDateTime() -> TimeOnly.FromDateTime() will always return default(TimeOnly). Dont know if it is better to explicitly throw here?
-------
Postgre time DateTime TimeSpan Convert.ToDateTime() throws InvalidCastException TimeOnly can't be a DateTime
Postgre time DateOnly TimeSpan Convert.ToDateTime() throws InvalidCastException TimeOnly can't be a DateOnly
Postgre time TimeOnly TimeSpan cast object arg to TimeSpan -> TimeOnly.FromTimeSpan()

I have adjusted the implementation of CommandUtils.As<T> according to the table above, and then wrote integration tests (only for postgreSql).

Note: I also wrote a code to exclude non-compatible input files for unit Interceptors tests (we dont need to run .netFx tests against DateOnly.input.cs, because .netFx does not support DateOnly and TimeOnly types).

Closes #116

@DeagleGross DeagleGross self-assigned this Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support DateOnly that was added in Dapper 2.1.37
1 participant