Skip to content

Adjust datetime handling and add tests#153

Merged
alex-clickhouse merged 10 commits intomainfrom
datetime-handling
Jan 4, 2026
Merged

Adjust datetime handling and add tests#153
alex-clickhouse merged 10 commits intomainfrom
datetime-handling

Conversation

@alex-clickhouse
Copy link
Copy Markdown
Collaborator

@alex-clickhouse alex-clickhouse commented Dec 30, 2025

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.

  • DateTime reading: columns without timezone now return DateTime with Kind=Unspecified; DateTime('UTC') returns Kind=Utc; non-UTC tz returns Unspecified (use GetDateTimeOffset for correct offsets)
  • DateTime writing: HttpParameterFormatter now preserves instants by sending Unix timestamps for Utc/Local and string values for Unspecified; bulk copy respects column timezones
  • Removes UseServerTimezone from ClickHouseDefaults, ClickHouseClientSettings, ClickHouseConnectionStringBuilder, connection string, equality/hash, and ToString
  • Connection no longer queries timezone(); server timezone is now available on ClickHouseCommand.ServerTimezone (from X-ClickHouse-Timezone header)
  • Simplifies TypeSettings and updates DateTime/DateTime64 type parsing and coercion
  • Adds extensive timezone tests, revises default-setting tests, updates samples in TestUtilities, adds DataTypes_002_DateTimeHandling.cs, and updates RELEASENOTES.md

Written by Cursor Bugbot for commit 162bf0c. This will update automatically on new commits. Configure here.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 30, 2025

Codecov Report

❌ Patch coverage is 90.90909% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...lickHouse.Driver/Formats/HttpParameterFormatter.cs 76.92% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

Comment thread ClickHouse.Driver/ADO/ClickHouseConnection.cs Outdated
Comment thread ClickHouse.Driver/ADO/ClickHouseConnection.cs Outdated
Comment thread ClickHouse.Driver/Formats/HttpParameterFormatter.cs
Comment thread ClickHouse.Driver.Tests/Types/TimezoneHandlingTests.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Comment thread ClickHouse.Driver/ADO/ClickHouseConnection.cs Outdated
Comment thread ClickHouse.Driver.Tests/Types/TimezoneHandlingTests.cs Outdated
Comment thread ClickHouse.Driver.Tests/Types/TimezoneHandlingTests.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.

Comment thread ClickHouse.Driver/ADO/ClickHouseConnection.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Comment thread examples/DataTypes_002_DateTimeHandling.cs Outdated
Comment thread ClickHouse.Driver/Types/AbstractDateTimeType.cs
Comment thread ClickHouse.Driver/Formats/HttpParameterFormatter.cs
Comment thread ClickHouse.Driver.Tests/Types/TimezoneHandlingTests.cs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@alex-clickhouse alex-clickhouse merged commit 0fa30f4 into main Jan 4, 2026
17 checks passed
@alex-clickhouse alex-clickhouse deleted the datetime-handling branch January 4, 2026 14:43
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.

2 participants