Skip to content

Commit

Permalink
TIMESTAMP->dt: Naming things
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Oct 18, 2022
1 parent 8894f95 commit eba6f89
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions docs/query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ For your reference, in the following examples, epoch 1658167836758 is

>>> import datetime
>>> tz_mst = datetime.timezone(datetime.timedelta(hours=7), name="MST")
>>> ccursor = connection.cursor(time_zone=tz_mst)
>>> cursor = connection.cursor(time_zone=tz_mst)

>>> ccursor.execute("SELECT datetime_tz FROM locations ORDER BY name")
>>> cursor.execute("SELECT datetime_tz FROM locations ORDER BY name")

>>> cursor.fetchone()
[datetime.datetime(2022, 7, 19, 1, 10, 36, 758000, tzinfo=datetime.timezone(datetime.timedelta(seconds=25200), 'MST'))]
Expand All @@ -280,30 +280,30 @@ Let's exercise all of them.

::

>>> ccursor.time_zone = datetime.timezone.utc
>>> ccursor.execute("SELECT datetime_tz FROM locations ORDER BY name")
>>> ccursor.fetchone()
>>> cursor.time_zone = datetime.timezone.utc
>>> cursor.execute("SELECT datetime_tz FROM locations ORDER BY name")
>>> cursor.fetchone()
[datetime.datetime(2022, 7, 18, 18, 10, 36, 758000, tzinfo=datetime.timezone.utc)]

>>> import pytz
>>> ccursor.time_zone = pytz.timezone("Australia/Sydney")
>>> ccursor.execute("SELECT datetime_tz FROM locations ORDER BY name")
>>> ccursor.fetchone()
>>> cursor.time_zone = pytz.timezone("Australia/Sydney")
>>> cursor.execute("SELECT datetime_tz FROM locations ORDER BY name")
>>> cursor.fetchone()
['foo', datetime.datetime(2022, 7, 19, 4, 10, 36, 758000, tzinfo=<DstTzInfo 'Australia/Sydney' AEST+10:00:00 STD>)]

>>> 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()
>>> cursor.time_zone = zoneinfo.ZoneInfo("Australia/Sydney")
>>> cursor.execute("SELECT datetime_tz FROM locations ORDER BY name")
>>> cursor.fetchone()
[datetime.datetime(2022, 7, 19, 4, 10, 36, 758000, tzinfo=zoneinfo.ZoneInfo(key='Australia/Sydney'))]

>>> ccursor.time_zone = "+0530"
>>> ccursor.execute("SELECT datetime_tz FROM locations ORDER BY name")
>>> ccursor.fetchone()
>>> cursor.time_zone = "+0530"
>>> cursor.execute("SELECT datetime_tz FROM locations ORDER BY name")
>>> cursor.fetchone()
[datetime.datetime(2022, 7, 18, 23, 40, 36, 758000, tzinfo=datetime.timezone(datetime.timedelta(seconds=19800), '+0530'))]


Expand Down

0 comments on commit eba6f89

Please sign in to comment.