diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | psycopg/adapter_datetime.c | 2 | ||||
-rw-r--r-- | tests/test_dates.py | 11 |
3 files changed, 19 insertions, 1 deletions
@@ -1,3 +1,10 @@ +2010-05-07 Daniele Varrazzo <daniele.varrazzo@gmail.com> + + * psycopg/adapter_datetime.c: Fixed TimestampFromTicks for second + values > 59.5. + + Bug reported and fixed by Jozsef Szalay on 2010-05-06 at 14:11:59.999920. + 2010-05-04 Daniele Varrazzo <daniele.varrazzo@gmail.com> * Added typecasters for arrays of specific MX/Py time-related types. diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index 24d158c..f684163 100644 --- a/psycopg/adapter_datetime.c +++ b/psycopg/adapter_datetime.c @@ -435,7 +435,7 @@ psyco_TimestampFromTicks(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)) { PyObject *value = Py_BuildValue("iiiiidO", diff --git a/tests/test_dates.py b/tests/test_dates.py index 1ffb15a..e9977c8 100644 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -478,6 +478,17 @@ if not hasattr(psycopg2._psycopg, 'MXDATETIME'): del mxDateTimeTests +class TimestampFromTicksTestCase(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): + 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_suite(): return unittest.TestLoader().loadTestsFromName(__name__) |