Skip to content

Commit ec32f96

Browse files
authored
Allow dehydration of datetimes with zoneinfo time zones (#625)
Closes #610
1 parent 4c81faf commit ec32f96

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

neo4j/time/hydration.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ def seconds_and_nanoseconds(dt):
156156
value = utc.localize(value)
157157
seconds, nanoseconds = seconds_and_nanoseconds(value)
158158
return Structure(b"d", seconds, nanoseconds)
159-
elif hasattr(tz, "zone") and tz.zone:
160-
# with named time zone
159+
elif hasattr(tz, "zone") and tz.zone and isinstance(tz.zone, str):
160+
# with named pytz time zone
161161
seconds, nanoseconds = seconds_and_nanoseconds(value)
162162
return Structure(b"f", seconds, nanoseconds, tz.zone)
163+
elif hasattr(tz, "key") and tz.key and isinstance(tz.key, str):
164+
# with named zoneinfo (Python 3.9+) time zone
165+
seconds, nanoseconds = seconds_and_nanoseconds(value)
166+
return Structure(b"f", seconds, nanoseconds, tz.key)
163167
else:
164168
# with time offset
165169
seconds, nanoseconds = seconds_and_nanoseconds(value)

0 commit comments

Comments
 (0)