yene commented on issue #11182:
URL: https://github.com/apache/airflow/issues/11182#issuecomment-700567768
The following example shows a DAG scheduled in a timezone different from the
macros (which use UTC), causing a **date mismatch**.
```
ENV TZ=Europe/Amsterdam
ENV AIRFLOW__CORE__DEFAULT_TIMEZONE=Europe/Amsterdam
```
```python
from airflow import models
from airflow.operators.bash_operator import BashOperator
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2020, 1, 1),
'catchup': False,
'retries': 0,
}
with models.DAG(
'example_timezone',
schedule_interval='0 0 * * *', # Schedules DAG at 0:0 in
Europe/Amsterdam timezone (e.g. 29.9.2020 00:00)
doc_md=__doc__,
default_args=default_args,
catchup=False,
) as dag:
print_date = BashOperator(
task_id='print_date',
bash_command='date', # Prints date with timezone Europe/Amsterdam
(e.g. 29.9.2020 00:00)
)
execution_date_tz = BashOperator(
task_id='execution_date_tz',
bash_command="echo {{ execution_date.in_timezone('Europe/Amsterdam')
}}", # Prints date with timezone Europe/Amsterdam (e.g. 29.9.2020 00:00)
)
execution_date = BashOperator(
task_id='execution_date',
bash_command='echo {{ execution_date }}', # Prints date with
timezone UTC (e.g. 28.9.2020 22:00)
)
ds = BashOperator(
task_id='execution_date_tz',
bash_command="echo {{ ds }}", # Prints date with timezone UTC (e.g.
28.9.2020)
)
print_date >> execution_date >> execution_date_tz >> ds
```
> Note: as reference, the Azure devops scheduler is always in UTC. But we
are a single timezone company and it would be comfortable to have everything in
one zone.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]