Taragolis commented on PR #34492:
URL: https://github.com/apache/airflow/pull/34492#issuecomment-1728301574

   > maybe we should see a first iteration and then figure out if we want to 
support non-pendulum timezone aware datetimes. I do not think we should, due to 
all the issues with the other implementations, but open to discussion.
   
   I'm just worry, if we only would serialize `datetime.datetime` and 
`pendulum.DataTime` with pendulum Timezone, then we potentially could breaks 
someone pipeline, because right now it is possible without any issues serialize 
datetime with UTC timezone regardless of `tzinfo` implementation. And different 
libraries use different `tzinfo` for timezones, for example
   - boto3: python-dateutils
   - psycopg2: own implementation
   - psycopg (formally v3): zoneinfo.ZoneInfo and 
backports.zoneinfo.ZoneInfo(Python < 3.9)
   
   In general you could compare `datetime.datetime` with different `tzinfo` 
implementation
   
   ```python
   from dateutil.tz import tzutc
   from datetime import datetime, timezone, timedelta
   from pendulum.tz.timezone import Timezone
   from zoneinfo import ZoneInfo
   from pendulum.tz import timezone as ptimezone
   from psycopg2.tz import FixedOffsetTimezone
   from pytz import UTC
   
   d1 = datetime(2021, 1, 1, tzinfo=timezone.utc)
   d2 = datetime(2021, 1, 1, tzinfo=Timezone("UTC"))
   d3 = datetime(2021, 1, 1, tzinfo=tzutc())
   d4 = datetime(2021, 1, 1, tzinfo=ZoneInfo("UTC"))
   d5 = datetime(2021, 1, 1, tzinfo=FixedOffsetTimezone(offset=0))
   d6 = datetime(2021, 1, 1, tzinfo=UTC)
   
   assert d1 == d2 == d3 == d4 == d5 == d6
   assert d1.tzname() == d2.tzname() == d3.tzname() == d4.tzname() == 
d6.tzname()
   assert d5.tzname() == "+00"  # psycopg2 uses Python 2.3 implementation ;-)
   
   assert d1.utcoffset() == d2.utcoffset()
   assert d1.utcoffset() == d3.utcoffset()
   assert d1.utcoffset() == d4.utcoffset()
   assert d1.utcoffset() == d5.utcoffset()
   assert d1.utcoffset() == d6.utcoffset()
   
   dl1 = datetime(2021, 6, 1, tzinfo=Timezone("Europe/London"))
   dl2 = datetime(2021, 6, 1, tzinfo=ZoneInfo("Europe/London"))
   dl3 = datetime(2021, 6, 1, tzinfo=timezone(timedelta(hours=1)))
   
   assert dl1 == dl2 == dl3
   
   dl1_from_name = datetime(2021, 6, 1, tzinfo=ptimezone(dl1.tzinfo.name))
   dl1_from_offset = datetime(2021, 6, 1, 
tzinfo=ptimezone(int(dl1.utcoffset().total_seconds())))
   
   assert dl1 == dl1_from_name == dl1_from_offset
   
   dl2_from_name = datetime(2021, 6, 1, tzinfo=ptimezone(dl2.tzinfo.key))
   dl2_from_offset = datetime(2021, 6, 1, 
tzinfo=ptimezone(int(dl2.utcoffset().total_seconds())))
   
   assert dl2 == dl2_from_name == dl2_from_offset
   
   dl3_from_offset = datetime(2021, 6, 1, 
tzinfo=ptimezone(int(dl3.utcoffset().total_seconds())))
   assert dl3 == dl3_from_offset
   ```
   
   Maybe we should try to serialize `datetime.datetime` but result of 
deserialization will always use Pendulum timezone regardless original one.
   
   In case of serialize just timezone I think it is fine to serialize only 
Pendulum one, and when we have min Python 3.9 we could discuss should we also 
serialize  `zoneinfo.ZoneInfo`
   
   
   


-- 
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]

Reply via email to