Fixed TimestampFromTicks for second values > 59.5.

Bug reported and fixed by Jozsef Szalay on 2010-05-06 at 14:11:59.999920.
This commit is contained in:
Daniele Varrazzo 2010-05-07 18:06:18 +01:00
parent b04bf41f99
commit afea19651c
3 changed files with 19 additions and 1 deletions

View File

@ -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.

View File

@ -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",

View File

@ -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__)