Skip to content

Prevent SQLite from messing with timezone offset of DateTime. #1374

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

Closed
wants to merge 1 commit into from

Conversation

ngbrown
Copy link
Contributor

@ngbrown ngbrown commented Oct 13, 2017

This addresses #1362 by writing all DateTime parameter values to SQLite as DateTimeKind.Unspecified.

This should work even when the connection string has ;DateTimeKind=Utc, as the ADO.Net driver uses that to mung all DateTime values to Utc on reading back, irregardless of how they were saved.

Copy link
Member

@fredericDelaporte fredericDelaporte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said in #1362, I think this hack should be configurable, if we really want to fix this SQLite issue on NHibernate side.

@@ -52,7 +52,7 @@ protected AbstractDateTimeType(SqlType sqlTypeDateTime) : base(sqlTypeDateTime)
/// <param name="dateValue">The <see cref="System.DateTime" /> to adjust.</param>
/// <returns>A <see cref="System.DateTime" />.</returns>
protected virtual DateTime AdjustDateTime(DateTime dateValue) =>
Kind == DateTimeKind.Unspecified ? dateValue : DateTime.SpecifyKind(dateValue, Kind);
DateTime.SpecifyKind(dateValue, Kind);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is really this change required? SQLite users working with DateTimeKind=UTC would have a legitimate grievance with this change, as it would wreck their reading of dates, causing them to be unspecified instead of being said as UTC, and forcing them to use NHibernate Utc types instead.

I do not think we should force unspecified unless really having a compelling reason to do it. I think the NHibernate "unspecified" types should have as semantic "no change at all to read date kind", as was doing TimestampType previously (which is now become DateTimeType.) The fact that previous DateTimeType, cutting fractional seconds, is losing the kind, was likely accidental design. (DateTimeNoMsType probably still does that indeed.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should stay the way it is without any configuration. See the unit test I created and my comment on the issue.

@hazzik
Copy link
Member

hazzik commented Oct 16, 2017

Replaced by #1378

@hazzik hazzik closed this Oct 16, 2017
@ngbrown ngbrown deleted the bug/1362 branch October 26, 2017 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants