Skip to content

fix: render Timestamp and TimestampTz up to 9999-12-31 23:59:59.999999 - #107

Merged
b41sh merged 1 commit into
databendlabs:mainfrom
TCeason:fix/timestamp-display-range
Nov 12, 2026
Merged

b41sh merged 1 commit into
databendlabs:mainfrom
TCeason:fix/timestamp-display-range

Conversation

@TCeason

@TCeason TCeason commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes the text rendering part of databendlabs/databend#21070.

Problem

Display for Timestamp and TimestampTz clamps the value to 9999-12-30T22:00:00Z before formatting, because that is the upper bound of jiff::Timestamp (it must stay valid in every offset). Databend's TIMESTAMP range ends at 9999-12-31 23:59:59.999999, so every later value inside a VARIANT is printed as 9999-12-30 22:00:00.000000. This affects query results, v::STRING, and NDJSON/CSV unloads, and a reload stores the changed value.

Changes

  • Convert the epoch microseconds (plus the offset for TimestampTz) to a jiff::civil::DateTime, which covers years -9999 to 9999, and format that. TimestampTz sets the offset on a BrokenDownTime so %z still works.
  • Values outside the civil range (for example i64::MAX micros, or a local time past year 9999) saturate to DateTime::MIN/DateTime::MAX, so formatting never panics, as before.
  • Output format is unchanged for values that were already rendered correctly.
  • No new dependency.

Tests

  • Added 13 cases to test_to_string: 9999-12-31 23:59:59, .999999, 9999-12-30 22:00:01, 0001-01-01, -1 micros, i64::MAX/i64::MIN, and TimestampTz with +0000, +0800, -0800 and local-time overflow.
  • The new cases fail on main (9999-12-30 22:00:00.000000) and pass with this change.
  • cargo test, cargo clippy --all-targets -- -D warnings and cargo fmt --check pass.
  • End to end: built Databend 652b12b49c against this branch and ran the reproduction from #21070 in a UTC session. Query results (HTTP and MySQL handlers), v::STRING, and NDJSON and CSV round trips now keep 9999-12-31 23:59:59. A Databend regression test with these cases fails 9 of 33 records on the current nightly and passes with this branch.
  • TimestampTz inside a VARIANT now renders the same local time as to_string(ts::TIMESTAMP_TZ) in Asia/Shanghai and America/Los_Angeles sessions.

Not addressed here: Timestamp text has no offset and Databend parses it back in the session time zone, so a text round trip in a non-UTC session shifts the value by the offset (and can now hit the range limit at the max end in negative offsets). That behavior is independent of this change and will be tracked separately in Databend.

AI assistance

Prepared with an AI coding assistant. @TCeason has read the full diff and is responsible for answering review questions.

The Display impls clamped values to 9999-12-30T22:00:00Z, the upper bound of
jiff::Timestamp, so later timestamps were printed as that instant. Build a
jiff::civil::DateTime from the epoch micros (plus the offset for TimestampTz)
instead; it covers the full year range. Values outside years -9999..=9999
saturate as before, so formatting still never panics.

Refs databendlabs/databend#21070
@TCeason

TCeason commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

cc @b41sh I think jiff is enough, no need to replace chrono.

@TCeason

TCeason commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

will fix in #108

@TCeason TCeason closed this Nov 12, 2026
@b41sh b41sh reopened this Nov 12, 2026
@b41sh
b41sh merged commit 5f6693c into databendlabs:main Nov 12, 2026
2 checks passed
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