From 2bb38318077543a20dd9a4b465d157b4f17f6a95 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Sun, 24 Mar 2019 18:19:32 -0400 Subject: [PATCH] Add time type conversion info to docs --- doc/src/usage.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/src/usage.rst b/doc/src/usage.rst index 08c6dce4..4f5c3ecc 100644 --- a/doc/src/usage.rst +++ b/doc/src/usage.rst @@ -633,6 +633,28 @@ to map `date.max` to :sql:`infinity`, for instance:: Of course it will not be possible to write the value of `date.max` in the database anymore: :sql:`infinity` will be stored instead. +.. _time-handling: + +Time handling +''''''''''''' + +The PostgreSQL :sql:`time` and Python `~datetime.time` types are not +fully bidirectional. + +Within PostgreSQL, the :sql:`time` type's maximum value of `24:00:00` is +treated as 24-hours later than the minimum value of `00:00:00`. + + >>> cur.execute("SELECT '24:00:00'::time - '00:00:00'::time") + >>> cur.fetchone()[0] + datetime.timedelta(days=1) + +However, Python's `~datetime.time` only supports times until `23:59:59`. +Retrieving a value of `24:00:00` results in a `~datetime.time` of `00:00:00`. + + >>> cur.execute("SELECT '24:00:00'::time, '00:00:00'::time") + >>> cur.fetchone() + (datetime.time(0, 0), datetime.time(0, 0)) + .. _adapt-list: