Skip to content

Conversation

@SML0127
Copy link
Contributor

@SML0127 SML0127 commented May 25, 2025


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

This PR closes #38337

In the previous logic (using datetime.datetime.today()), if server's timezone is UTC, target_datetime for TimeSensor could be incorrectly.

For example, when the user intended to use Asia/Singapore timezone and server timezone is UTC, taget time 2025-01-27 07:00:00+08:00 might be incorrectly converted to 2025-01-25 23:00:00 UTC instead of 2025-01-26 23:00:00 UTC.
(This assumes the current time is 2025-01-26 23:00:00 UTC, which is 2025-01-27 07:00:00 in Asia/Singapore.)

This happens because the local date 2025-01-26 is combined with the target time 07:00:00, resulting in 2025-01-26 07:00:00 in local time. And then this datetime is converted to UTC using convert_to_utc, it becomes 2025-01-25 23:00:00 UTC.

To fix this, pendulum.now(tz=str(self.dag.timezone)) is used instead of datetime.datetime.today().

All unit tests for TimeSensor passed
image

@boring-cyborg
Copy link

boring-cyborg bot commented May 25, 2025

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@SML0127 SML0127 force-pushed the feature/support_tz_for_date_in_timesensor branch from ddf74e8 to 81144d0 Compare May 25, 2025 09:57
@SML0127 SML0127 changed the title Feature/support tz for date in timesensor Add timzone support for date calculation in TimeSensor May 25, 2025
@SML0127 SML0127 changed the title Add timzone support for date calculation in TimeSensor Add timezone support for date calculation in TimeSensor May 25, 2025
@SML0127
Copy link
Contributor Author

SML0127 commented May 25, 2025

@uranusjr Thank you for the kind and detiled comments. I've addressed the points you mentioned.

@SML0127
Copy link
Contributor Author

SML0127 commented May 25, 2025

@uranusjr Thank you for the kind and detiled comments. I've addressed the points you mentioned.

unit test results
image

@SML0127 SML0127 force-pushed the feature/support_tz_for_date_in_timesensor branch from 03792d9 to e5d886c Compare May 26, 2025 05:23
@Lee-W Lee-W merged commit 639b23e into apache:main May 26, 2025
96 checks passed
@boring-cyborg
Copy link

boring-cyborg bot commented May 26, 2025

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

dadonnelly316 pushed a commit to dadonnelly316/airflow that referenced this pull request May 26, 2025
* edit: consider dag timezone when combine target date in TimeSensor

* add: add test code for the case that server timezone is different with user intended timezone

* resolve pre-commit

* resolved pre-commit
@dwreeves
Copy link
Contributor

Thank you for resolving the issue! ❤️

sanederchik pushed a commit to sanederchik/airflow that referenced this pull request Jun 7, 2025
* edit: consider dag timezone when combine target date in TimeSensor

* add: add test code for the case that server timezone is different with user intended timezone

* resolve pre-commit

* resolved pre-commit
jose-lehmkuhl pushed a commit to jose-lehmkuhl/airflow that referenced this pull request Jul 11, 2025
* edit: consider dag timezone when combine target date in TimeSensor

* add: add test code for the case that server timezone is different with user intended timezone

* resolve pre-commit

* resolved pre-commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support timezone-aware times for TimeSensor and TimeSensorAsync.

4 participants