diff --git a/ChangeLog b/ChangeLog index 205c47a4..f4a81e17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ Bug reported and fixed by Jozsef Szalay on 2010-05-06 at 14:11:59.999920. + * psycopg/adapter_datetime.c: Fixed same bug for TimeFromTicks. + 2010-05-04 Daniele Varrazzo * Added typecasters for arrays of specific MX/Py time-related types. diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index f6841634..8d5aa3dd 100644 --- a/psycopg/adapter_datetime.c +++ b/psycopg/adapter_datetime.c @@ -389,7 +389,7 @@ psyco_DateFromTicks(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "d", &ticks)) return NULL; - t = (time_t)round(ticks); + t = (time_t)floor(ticks); if (localtime_r(&t, &tm)) { args = Py_BuildValue("iii", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday); if (args) { @@ -411,7 +411,7 @@ psyco_TimeFromTicks(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args,"d", &ticks)) return NULL; - t = (time_t)round(ticks); + t = (time_t)floor(ticks); ticks -= (double)t; if (localtime_r(&t, &tm)) { args = Py_BuildValue("iid", tm.tm_hour, tm.tm_min, diff --git a/tests/test_dates.py b/tests/test_dates.py index e9977c84..08636d76 100644 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -478,16 +478,27 @@ if not hasattr(psycopg2._psycopg, 'MXDATETIME'): del mxDateTimeTests -class TimestampFromTicksTestCase(unittest.TestCase): +class FromTicksTestCase(unittest.TestCase): # bug "TimestampFromTicks() throws ValueError (2-2.0.14)" # reported by Jozsef Szalay on 2010-05-06 - def test_value_error_sec_59_99(self): + def test_timestamp_value_error_sec_59_99(self): from datetime import datetime s = psycopg2.TimestampFromTicks(1273173119.99992) self.assertEqual(s.adapted, datetime(2010, 5, 6, 14, 11, 59, 999920, tzinfo=FixedOffsetTimezone(-5 * 60))) + def test_date_value_error_sec_59_99(self): + from datetime import date + s = psycopg2.DateFromTicks(1273173119.99992) + self.assertEqual(s.adapted, date(2010, 5, 6)) + + def test_time_value_error_sec_59_99(self): + from datetime import time + s = psycopg2.TimeFromTicks(1273173119.99992) + self.assertEqual(s.adapted, + time(20, 11, 59, 999920)) + def test_suite(): return unittest.TestLoader().loadTestsFromName(__name__)