bolkedebruin commented on issue #34673:
URL: https://github.com/apache/airflow/issues/34673#issuecomment-1740432703
I dont think that is the right approach as that would convert the timezone
to UTC even if it is not:
```
sample_data = datetime(2021, 1, 1, tzinfo=ZoneInfo("Europe/Paris"))
sample_data = convert_to_utc(sample_data) # <- This will convert tz to
pendulum timezone
ser_data = serialize(sample_data)
print(ser_data)
({'timestamp': 1609455600.0, 'tz': ('UTC',
'pendulum.tz.timezone.FixedTimezone', 1, True)}, 'pendulum.datetime.DateTime',
2, True)
```
I think the best way forward is to just extend the timezone serializer to
deal with ZoneInfo and pytz. Relying on `pendulum.instance()` could also work,
but that would convert the timezone to a FixedTimezone.
This is from Pendulum master:
```
def _get_tzinfo_name(tzinfo: datetime.tzinfo | None) -> str | None:
if tzinfo is None:
return None
if hasattr(tzinfo, "key"):
# zoneinfo timezone
return cast(zoneinfo.ZoneInfo, tzinfo).key
elif hasattr(tzinfo, "name"):
# Pendulum timezone
return cast(Timezone, tzinfo).name
elif hasattr(tzinfo, "zone"):
# pytz timezone
return tzinfo.zone # type: ignore[no-any-return]
return None
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]