This is an automated email from the ASF dual-hosted git repository.

claudevdm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new addb3a22edf Add support for zoneinfo UTC timestamps (#40613)
addb3a22edf is described below

commit addb3a22edfc33370c94c9f500f1daabf9e7730b
Author: Jack McCluskey <[email protected]>
AuthorDate: Thu Oct 15 12:02:23 2026 -0400

    Add support for zoneinfo UTC timestamps (#40613)
    
    * Add support for zoneinfo UTC timestamps
    
    * review feedback
---
 sdks/python/apache_beam/utils/timestamp.py      | 4 +++-
 sdks/python/apache_beam/utils/timestamp_test.py | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/sdks/python/apache_beam/utils/timestamp.py 
b/sdks/python/apache_beam/utils/timestamp.py
index 81d8430d3af..9ef900a2671 100644
--- a/sdks/python/apache_beam/utils/timestamp.py
+++ b/sdks/python/apache_beam/utils/timestamp.py
@@ -26,6 +26,7 @@ For internal use only; no backwards-compatibility guarantees.
 import datetime
 import re
 import time
+import zoneinfo
 from typing import Optional
 from typing import Union
 from typing import overload
@@ -166,7 +167,8 @@ class Timestamp(object):
           "dt has no timezone info " +
           "(https://docs.python.org/3/library/datetime.html"; +
           "#aware-and-naive-objects): %s" % dt)
-    if dt.tzinfo != pytz.utc and dt.tzinfo != datetime.timezone.utc:
+    if dt.tzinfo != pytz.utc and dt.tzinfo != datetime.timezone.utc and not (
+        isinstance(dt.tzinfo, zoneinfo.ZoneInfo) and dt.tzinfo.key == 'UTC'):
       raise ValueError('dt not in UTC: %s' % dt)
     duration = dt - cls._epoch_datetime_utc()
     # Avoid total_seconds(): its float result can be off by a microsecond.
diff --git a/sdks/python/apache_beam/utils/timestamp_test.py 
b/sdks/python/apache_beam/utils/timestamp_test.py
index ebdd42d3702..fd004233398 100644
--- a/sdks/python/apache_beam/utils/timestamp_test.py
+++ b/sdks/python/apache_beam/utils/timestamp_test.py
@@ -21,6 +21,7 @@
 
 import datetime
 import unittest
+import zoneinfo
 
 import pytz
 from google.protobuf import duration_pb2
@@ -86,6 +87,10 @@ class TimestampTest(unittest.TestCase):
         Timestamp.from_utc_datetime(
             datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)),
         Timestamp(0))
+    self.assertEqual(
+        Timestamp.from_utc_datetime(
+            datetime.datetime(1970, 1, 1, tzinfo=zoneinfo.ZoneInfo("UTC"))),
+        Timestamp(0))
     with self.assertRaisesRegex(ValueError, r'UTC'):
       Timestamp.from_utc_datetime(
           datetime.datetime(1970, 1, 1, tzinfo=pytz.timezone('US/Eastern')))

Reply via email to