Skip to content

minor(fix): correct to_date results for formatted pre-epoch datetimes - #24049

Merged
kumarUjjawal merged 1 commit into
apache:mainfrom
buraksenn:use-div-euclid-for-before-epoch
Aug 2, 2026
Merged

minor(fix): correct to_date results for formatted pre-epoch datetimes#24049
kumarUjjawal merged 1 commit into
apache:mainfrom
buraksenn:use-div-euclid-for-before-epoch

Conversation

@buraksenn

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • Closes N\A but I can open an issue

Rationale for this change

Formatted to_date inputs are parsed as milliseconds since the Unix epoch and then converted to Date32 days. Integer division truncates toward zero, so negative sub-day timestamps are incorrectly mapped to day 0 instead of day -1.

-- DataFusion before this change
SELECT to_date('1969-12-31 12:00:00', '%Y-%m-%d %H:%M:%S');
-- 1970-01-01

-- PostgreSQL
SELECT to_date('1969-12-31 12:00:00', 'YYYY-MM-DD HH24:MI:SS');
-- 1969-12-31

-- DuckDB
SELECT CAST(strptime('1969-12-31 12:00:00', '%Y-%m-%d %H:%M:%S') AS DATE);
-- 1969-12-31

What changes are included in this PR?

Use Euclidean division when converting formatted timestamp milliseconds to days, preserving the correct date for timestamps before the Unix epoch.

Are these changes tested?

Yes new slt test for this case.

Are there any user-facing changes?

No API changes. Formatted pre-epoch datetimes now return the correct date.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Aug 1, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.86%. Comparing base (455a3ad) to head (6d54bdf).
⚠️ Report is 26 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24049      +/-   ##
==========================================
+ Coverage   80.84%   80.86%   +0.01%     
==========================================
  Files        1096     1101       +5     
  Lines      373832   375446    +1614     
  Branches   373832   375446    +1614     
==========================================
+ Hits       302240   303587    +1347     
- Misses      53563    53767     +204     
- Partials    18029    18092      +63     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kumarUjjawal kumarUjjawal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

@kumarUjjawal

Copy link
Copy Markdown
Contributor

Thank you @buraksenn

@kumarUjjawal
kumarUjjawal added this pull request to the merge queue Aug 2, 2026
Merged via the queue into apache:main with commit eb8e38e Aug 2, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants