Convert Postgres time 24:00 into 00:00

Fix ticket #278.
This commit is contained in:
Daniele Varrazzo 2015-02-08 00:41:50 +00:00
parent 2332f2c99e
commit d3c1ad5945
3 changed files with 16 additions and 0 deletions

1
NEWS
View File

@ -21,6 +21,7 @@ What's new in psycopg 2.5.5
- Named cursors used as context manager don't swallow the exception on exit
(:ticket:`#262`).
- PostgreSQL time 24:00 is converted to Python 00:00 (:ticket:`#278`).
What's new in psycopg 2.5.4

View File

@ -164,6 +164,9 @@ typecast_parse_time(const char* s, const char** t, Py_ssize_t* len,
while (usd++ < 6) *us *= 10;
}
/* 24:00:00 -> 00:00:00 (ticket #278) */
if (*hh == 24) { *hh = 0; }
return cz;
}

View File

@ -319,6 +319,18 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin):
from datetime import timedelta
self._test_type_roundtrip_array(timedelta(seconds=30))
def test_time_24(self):
from datetime import time
t = self.execute("select '24:00'::time;")
self.assertEqual(t, time(0, 0))
t = self.execute("select '24:00+05'::timetz;")
self.assertEqual(t, time(0, 0, tzinfo=FixedOffsetTimezone(300)))
t = self.execute("select '24:00+05:30'::timetz;")
self.assertEqual(t, time(0, 0, tzinfo=FixedOffsetTimezone(330)))
# Only run the datetime tests if psycopg was compiled with support.
if not hasattr(psycopg2.extensions, 'PYDATETIME'):