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:

github-merge-queue bot pushed a commit that referenced this pull request Oct 24, 2025
## Which issue does this PR close?

- Relates #18062 
- Relates #18065

## Rationale for this change

We disabled these tests because CI was failing on main.

The test: `current_date() = cast(now() as date)` was added in #18034 
requires `now` to use configured timezone, but it is only available
after #18017.

Since #18017 has been merged, these tests should be enable.

## What changes are included in this PR?

This reverts commit a65a2cb.

## Are these changes tested?

Yes.

## Are there any user-facing changes?
No.
tobixdev pushed a commit to tobixdev/datafusion that referenced this pull request Nov 2, 2025
* Feat: Make current_date aware of execution timezone.

* CI Fixes: Rectify assertion error of slt and update scalar_functions.md

* CI Fixes: Comment out flaky test involving now().

* CI Fixes: Resolve slt error.

* Feat: Add helper function to calculate current_date and fix tests.

* Chore: Refactor timezone conversion logic.
tobixdev pushed a commit to tobixdev/datafusion that referenced this pull request Nov 2, 2025
## Which issue does this PR close?

- Relates apache#18062 
- Relates apache#18065

## Rationale for this change

We disabled these tests because CI was failing on main.

The test: `current_date() = cast(now() as date)` was added in apache#18034 
requires `now` to use configured timezone, but it is only available
after apache#18017.

Since apache#18017 has been merged, these tests should be enable.

## What changes are included in this PR?

This reverts commit a65a2cb.

## Are these changes tested?

Yes.

## Are there any user-facing changes?
No.
@codetyri0n codetyri0n deleted the current_date branch November 19, 2025 17:52
EeshanBembi pushed a commit to EeshanBembi/datafusion that referenced this pull request Nov 24, 2025
## Which issue does this PR close?

- Relates apache#18062 
- Relates apache#18065

## Rationale for this change

We disabled these tests because CI was failing on main.

The test: `current_date() = cast(now() as date)` was added in apache#18034 
requires `now` to use configured timezone, but it is only available
after apache#18017.

Since apache#18017 has been merged, these tests should be enable.

## What changes are included in this PR?

This reverts commit a65a2cb.

## Are these changes tested?

Yes.

## Are there any user-facing changes?
No.
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