Skip to content

Conversation

codetyri0n
Copy link
Contributor

@codetyri0n codetyri0n commented Oct 13, 2025

Which issue does this PR close?

Rationale for this change

  • current_date previously used only UTC. With this change it can recognize the timezone that can be set for execution.

What changes are included in this PR?

  • current_date() returns a timezone aware date via the 'datafusion.execution.time_zone' config option.

Are these changes tested?

  • Tested in datafusion CLI and added slt covering popular scenarios.

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Oct 13, 2025
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Oct 13, 2025
@codetyri0n codetyri0n requested a review from comphead October 13, 2025 19:11
);

// Get timezone from config and convert to local time
let days = if let Some(config) = info.execution_props().config_options() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can rewrite this into something more idiomatic

let days = info
    .execution_props()
    .config_options()
    .and_then(|config| config.execution.time_zone.parse::<Tz>().ok())
    .map_or_else(
        || datetime_to_days(&now_ts),
        |tz| {
            let local_now = tz.from_utc_datetime(&now_ts.naive_utc());
            datetime_to_days(&local_now)
        },
    );

@codetyri0n codetyri0n requested a review from comphead October 14, 2025 14:48
Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

Thanks @codetyri0n it looks good to me

@comphead comphead added this pull request to the merge queue Oct 14, 2025
Merged via the queue into apache:main with commit 77ec319 Oct 14, 2025
29 checks passed

#Test 4: Verify current_date matches cast(now() as date) in the same timezone
query B
SELECT current_date() = cast(now() as date);
Copy link
Contributor

Choose a reason for hiding this comment

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

For some reason, this test appears to be failing on main:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make current_date aware of execution timezone

3 participants