diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-05-07 18:28:31 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-05-15 14:27:24 +0100 |
commit | c46a1dad630b108892dcc282c882a27c1d5deafa (patch) | |
tree | 5abdcd6d8fbcc161560a0d50fac9a52e80ade710 | |
parent | afea19651cd5bcdcfb58c858a41cb2512b2879da (diff) | |
download | psycopg2-c46a1dad630b108892dcc282c882a27c1d5deafa.tar.gz |
Fixed TimeFromTicks for second values > 59.5.
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | psycopg/adapter_datetime.c | 4 | ||||
-rw-r--r-- | tests/test_dates.py | 15 |
3 files changed, 17 insertions, 4 deletions
@@ -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 <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 f684163..8d5aa3d 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 e9977c8..08636d7 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__) |