-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Add timezone support for date calculation in TimeSensor #51043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add timezone support for date calculation in TimeSensor #51043
Conversation
|
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)
|
ddf74e8 to
81144d0
Compare
providers/standard/src/airflow/providers/standard/sensors/time.py
Outdated
Show resolved
Hide resolved
|
@uranusjr Thank you for the kind and detiled comments. I've addressed the points you mentioned. |
|
03792d9 to
e5d886c
Compare
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
* 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
|
Thank you for resolving the issue! ❤️ |
* 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
* 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

^ 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.rstor{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_datetimefor TimeSensor could be incorrectly.For example, when the user intended to use
Asia/Singaporetimezone and server timezone isUTC, taget time2025-01-27 07:00:00+08:00might be incorrectly converted to2025-01-25 23:00:00 UTCinstead of2025-01-26 23:00:00 UTC.(This assumes the current time is
2025-01-26 23:00:00 UTC, which is2025-01-27 07:00:00in Asia/Singapore.)This happens because the local date
2025-01-26is combined with the target time07:00:00, resulting in2025-01-26 07:00:00in local time. And then this datetime is converted to UTC usingconvert_to_utc, it becomes2025-01-25 23:00:00 UTC.To fix this,
pendulum.now(tz=str(self.dag.timezone))is used instead ofdatetime.datetime.today().All unit tests for TimeSensor passed
