Adjust datetime handling and add tests#153
Merged
alex-clickhouse merged 10 commits intomainfrom Jan 4, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors DateTime handling to respect DateTime.Kind property, fixing a behavior where all DateTime values were previously treated as wall-clock time regardless of their Kind. The changes ensure UTC and Local DateTime values now preserve their instant (point in time) rather than being reinterpreted as wall-clock time in the target timezone.
Key changes:
- UTC/Local DateTime values now preserve their instant when written to ClickHouse columns
- Unspecified DateTime values continue to be treated as wall-clock time in the target timezone (unchanged)
- Server timezone discovery now uses HTTP response headers (
X-ClickHouse-Timezone) instead of a separate query - HTTP parameter formatting updated to send UTC/Local DateTime as Unix timestamps and Unspecified as ISO strings
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| RELEASENOTES.md | Documents breaking changes in DateTime.Kind handling and new timezone discovery approach |
| ClickHouse.Driver/Types/AbstractDateTimeType.cs | Adds explicit handling for UTC/Local DateTime.Kind when coercing to DateTimeOffset |
| ClickHouse.Driver/Formats/HttpParameterFormatter.cs | Updates DateTime formatting to send Unix timestamps for UTC/Local and strings for Unspecified |
| ClickHouse.Driver/ADO/ClickHouseConnection.cs | Removes timezone from version query and extracts it from HTTP headers instead |
| ClickHouse.Driver.Tests/Utilities/TestUtilities.cs | Updates DateTime64 test samples to use clearer date values and better precision testing |
| ClickHouse.Driver.Tests/Types/TimezoneHandlingTests.cs | Adds comprehensive test coverage for DateTime.Kind handling across read/write paths |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rewriting datetime handling after discovering that the docs did not correctly describe how the system works. Now more consistent and predictable in terms of timezone handling. See release notes for details.
Docs updated in accordance with these changes here.
Note
Introduces predictable DateTime behavior and removes implicit server timezone usage.
DateTimewithKind=Unspecified;DateTime('UTC')returnsKind=Utc; non-UTC tz returnsUnspecified(useGetDateTimeOffsetfor correct offsets)HttpParameterFormatternow preserves instants by sending Unix timestamps forUtc/Localand string values forUnspecified; bulk copy respects column timezonesUseServerTimezonefromClickHouseDefaults,ClickHouseClientSettings,ClickHouseConnectionStringBuilder, connection string, equality/hash, andToStringtimezone(); server timezone is now available onClickHouseCommand.ServerTimezone(fromX-ClickHouse-Timezoneheader)TypeSettingsand updatesDateTime/DateTime64type parsing and coercionTestUtilities, addsDataTypes_002_DateTimeHandling.cs, and updatesRELEASENOTES.mdWritten by Cursor Bugbot for commit 162bf0c. This will update automatically on new commits. Configure here.