From b031721dea04e1249aabdebe4cef77f29145b49f Mon Sep 17 00:00:00 2001 From: Daiyi Peng Date: Sat, 1 Nov 2025 15:07:01 -0700 Subject: [PATCH] Fix Python 3.9 and 3.10 PiperOrigin-RevId: 826946999 --- pyglove/core/typing/type_conversion_test.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyglove/core/typing/type_conversion_test.py b/pyglove/core/typing/type_conversion_test.py index 8644a02..ad88ac1 100644 --- a/pyglove/core/typing/type_conversion_test.py +++ b/pyglove/core/typing/type_conversion_test.py @@ -13,6 +13,7 @@ # limitations under the License. import calendar import datetime +import sys import typing import unittest @@ -130,12 +131,16 @@ def test_int_to_float(self): def test_datetime_to_int(self): """Test built-in converter between int and datetime.datetime.""" timestamp = calendar.timegm(datetime.datetime.now().timetuple()) - now = datetime.datetime.fromtimestamp(timestamp, datetime.UTC) + if sys.version_info >= (3, 11): + now = datetime.datetime.fromtimestamp(timestamp, datetime.UTC) + else: + now = datetime.datetime.utcfromtimestamp(timestamp) self.assertEqual(vs.Object(datetime.datetime).apply(timestamp), now) self.assertEqual(vs.Int().apply(now), timestamp) self.assertEqual( type_conversion.get_json_value_converter(datetime.datetime)(now), - timestamp) + timestamp + ) def test_keypath_to_str(self): """Test built-in converter between string and KeyPath."""