Skip to content

Commit 4e20913

Browse files
amotlmfussenegger
andcommitted
Update documentation about obtaining timezone-aware timestamps
Co-authored-by: Mathias Fußenegger <[email protected]>
1 parent 6235bcc commit 4e20913

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Unreleased
1111
- SQLAlchemy DDL: Allow setting ``server_default`` on columns to enable
1212
server-generated defaults. Thanks, @JanLikar.
1313

14-
- Allow handling "aware" datetime values with time zone info when inserting or updating.
14+
- Allow handling datetime values tagged with time zone info when inserting or updating.
1515

1616

1717
2023/04/18 0.31.1

docs/by-example/client.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ Refresh locations:
142142
Updating Data
143143
=============
144144

145-
Both when inserting or updating data, values for ``TIMESTAMP`` columns can be obtained
146-
in different formats. Both literal strings and datetime objects are supported.
145+
Values for ``TIMESTAMP`` columns can be obtained as a string literal, ``date``,
146+
or ``datetime`` object. If it contains timezone information, it is converted to
147+
UTC, and the timezone information is discarded.
147148

148149
>>> import datetime as dt
149150
>>> timestamp_full = "2023-06-26T09:24:00.123+02:00"

docs/data-types.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ __ https://crate.io/docs/crate/reference/en/latest/general/ddl/data-types.html#c
9999

100100
.. NOTE::
101101

102-
Values of ``TIMESTAMP`` columns will always be stored using a ``LONG`` type,
103-
representing the `Unix time`_ (epoch) timestamp, i.e. number of seconds which
104-
have passed since 00:00:00 UTC on Thursday, 1 January 1970.
102+
When using ``date`` or ``datetime`` objects with ``timezone`` information,
103+
the value is implicitly converted to a `Unix time`_ (epoch) timestamp, i.e.
104+
the number of seconds which have passed since 00:00:00 UTC on
105+
Thursday, 1 January 1970.
105106

106107
This means, when inserting or updating records using timezone-aware Python
107-
``datetime`` objects, timezone information will not be preserved. If you
108-
need to store it, you will need to use a separate column.
108+
``date`` or ``datetime`` objects, timezone information will not be
109+
preserved. If you need to store it, you will need to use a separate column.
109110

110111

111112
.. _data-types-sqlalchemy:

0 commit comments

Comments
 (0)