ecerulm commented on pull request #16631:
URL: https://github.com/apache/airflow/pull/16631#issuecomment-867612620
Just for clarification,
The whole `pendulum.tz.timezone.xxx` behaviour is a bit confusing. The
current codebase assumes that if you get a timezone "name" (with `.name`) you
can reconstruct a `datetime.tzinfo` with `pendulum.timezone(that_name)` which
is **only** true in certain conditions...
* for **many** "named" timezones like `UTC`, `Europe/Stockholm`, `CET`,etc
this holds true and that's what people had to use before in airflow.
* for all offset timezones like `+01:00`, etc this is **not true** and it
will raise `InvalidTimezone`
Besides that, there are some other pendulum/`datetime.tzinfo` oddities that
prevent some simplications.
* you can't just use `.tzname()`, because you need an actual datetime in
addition to the timezone to get the name.
* even if you just took the dag.start_date + dag.timezone (or the
dag.start_date.tzinfo), `tzname()` can give back a named timezone like CEST
that cannot be converted back to an actual `datetime.tzinfo` object by
`pendulum.timezone`) .
```
start_date = pendulum.datetime(2021,1,1,tzinfo=timezone.utc) # as dag
start_date is converted to utc
timezone = pendulum.timezone("Europe/Stockholm") # dag.timezone keeps the
"original" timezone that came in the start_date argument to the constructor
timezone.tzname(start_date) # returns 'CEST'
pendulum.timezone(timezone.tzname(start_date)) # raises InvalidTimezone
```
--
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]