Skip to content

Commit

Permalink
TIMESTAMP->dt: Use backports.zoneinfo on Python<3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Oct 18, 2022
1 parent 9ef9d61 commit 135caf7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
6 changes: 5 additions & 1 deletion docs/query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ Let's exercise all of them.
>>> ccursor.fetchone()
['foo', datetime.datetime(2022, 7, 19, 4, 10, 36, 758000, tzinfo=<DstTzInfo 'Australia/Sydney' AEST+10:00:00 STD>)]

>>> import zoneinfo
>>> try:
... import zoneinfo
... except ModuleNotFoundError:
... from backports import zoneinfo

>>> ccursor.time_zone = zoneinfo.ZoneInfo("Australia/Sydney")
>>> ccursor.execute("SELECT datetime_tz FROM locations ORDER BY name")
>>> ccursor.fetchone()
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def read(path):
},
extras_require=dict(
sqlalchemy=['sqlalchemy>=1.0,<1.5',
'geojson>=2.5.0'],
'geojson>=2.5.0',
'backports.zoneinfo<1; python_version<"3.9"'],
test=['tox>=3,<4',
'zope.testing>=4,<5',
'zope.testrunner>=5,<6',
Expand Down
13 changes: 10 additions & 3 deletions src/crate/client/doctests/cursor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,18 @@ Let's exercise all of them::
>>> cursor.fetchone()
['foo', datetime.datetime(2022, 7, 19, 4, 10, 36, 758000, tzinfo=<DstTzInfo 'Australia/Sydney' AEST+10:00:00 STD>)]

>>> import zoneinfo
>>> try:
... import zoneinfo
... except ModuleNotFoundError:
... from backports import zoneinfo
>>> cursor.time_zone = zoneinfo.ZoneInfo("Australia/Sydney")
>>> cursor.execute('')
>>> cursor.fetchone()
['foo', datetime.datetime(2022, 7, 19, 4, 10, 36, 758000, tzinfo=zoneinfo.ZoneInfo(key='Australia/Sydney'))]
>>> record = cursor.fetchone()
>>> record
['foo', datetime.datetime(2022, 7, 19, 4, 10, 36, 758000, ...zoneinfo.ZoneInfo(key='Australia/Sydney'))]

>>> record[1].tzname()
'AEST'

>>> cursor.time_zone = "+0530"
>>> cursor.execute('')
Expand Down
5 changes: 4 additions & 1 deletion src/crate/client/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
# software solely pursuant to the terms of the relevant commercial agreement.

import datetime
import zoneinfo
from ipaddress import IPv4Address
from unittest import TestCase
from unittest.mock import MagicMock
try:
import zoneinfo
except ModuleNotFoundError:
from backports import zoneinfo

import pytz

Expand Down

0 comments on commit 135caf7

Please sign in to comment.