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

Support the new BCL DateOnly and TimeOnly structs #963

Closed
roji opened this issue Mar 25, 2021 · 7 comments
Closed

Support the new BCL DateOnly and TimeOnly structs #963

roji opened this issue Mar 25, 2021 · 7 comments
Assignees
Milestone

Comments

@roji
Copy link

roji commented Mar 25, 2021

New DateOnly and TimeOnly structs are being introduced to .NET 6 as alternatives to DateTime (dotnet/runtime#49036).

@bgrainger
Copy link
Member

bgrainger commented Mar 25, 2021

As a parameter value, DateOnly could map to DATE, and TimeOnly to TIME.

When reading (e.g., with GetFieldValue<T>?) need to decide if extra data (e.g., GetFieldValue<DateOnly> on a DATETIME column, or GetFieldValue<TimeOnly> on a TIME column that is > 24 hrs) is just truncated/silently dropped, or causes an exception.

@mattjohnsonpint
Copy link

Please note that the final names for these types are DateOnly and TimeOnly and that they are now merged into the main branch for the next version of .NET 6 (preview 4 likely). Please rename the title of this issue accordingly. Thanks.

@bgrainger bgrainger changed the title Support the new BCL DateOnly and TimeOfDay structs Support the new BCL DateOnly and TimeOnly structs Apr 15, 2021
@bgrainger bgrainger self-assigned this May 25, 2021
@bgrainger
Copy link
Member

The commit written for this doesn't add support for converting from MySqlDateTime. That struct mostly exists for backwards compatibility with MySQL Connector/NET. Converting from it to DateOnly has a simple workaround: DateOnly.FromDateTime(mySqlDateTime.GetDateTime()).

@Germs2004
Copy link

Thank you for this great project. I added a vote and wanted to point out that implementing this Issue would support the project's homepage that says it's "cutting edge" and the tutorial that says it already supports DateOnly.

A connection string option to opt in is good for backwards compatibility, though the other opinion is that anyone who wants to intentionally mismatch a DATE field to a DateTime variable should be the ones who have to opt out via a connection string option.

@bgrainger
Copy link
Member

@Germs2004 This was implemented in MySqlConnector 2.0.0.

@bgrainger
Copy link
Member

@Germs2004 I created #1451 to track changing the default behaviour.

@Germs2004
Copy link

@Germs2004 I created #1451 to track changing the default behaviour.

Thank you, that new issue is perfect. And my apologies, I didn't notice that this issue was already closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants