mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-25 05:00:32 +03:00
Fixed TimeFromTicks for second values > 59.5.
This commit is contained in:
parent
afea19651c
commit
c46a1dad63
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
Bug reported and fixed by Jozsef Szalay on 2010-05-06 at 14:11:59.999920.
|
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>
|
2010-05-04 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||||
|
|
||||||
* Added typecasters for arrays of specific MX/Py time-related types.
|
* Added typecasters for arrays of specific MX/Py time-related types.
|
||||||
|
|
|
@ -389,7 +389,7 @@ psyco_DateFromTicks(PyObject *self, PyObject *args)
|
||||||
if (!PyArg_ParseTuple(args, "d", &ticks))
|
if (!PyArg_ParseTuple(args, "d", &ticks))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
t = (time_t)round(ticks);
|
t = (time_t)floor(ticks);
|
||||||
if (localtime_r(&t, &tm)) {
|
if (localtime_r(&t, &tm)) {
|
||||||
args = Py_BuildValue("iii", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
|
args = Py_BuildValue("iii", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
|
||||||
if (args) {
|
if (args) {
|
||||||
|
@ -411,7 +411,7 @@ psyco_TimeFromTicks(PyObject *self, PyObject *args)
|
||||||
if (!PyArg_ParseTuple(args,"d", &ticks))
|
if (!PyArg_ParseTuple(args,"d", &ticks))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
t = (time_t)round(ticks);
|
t = (time_t)floor(ticks);
|
||||||
ticks -= (double)t;
|
ticks -= (double)t;
|
||||||
if (localtime_r(&t, &tm)) {
|
if (localtime_r(&t, &tm)) {
|
||||||
args = Py_BuildValue("iid", tm.tm_hour, tm.tm_min,
|
args = Py_BuildValue("iid", tm.tm_hour, tm.tm_min,
|
||||||
|
|
|
@ -478,16 +478,27 @@ if not hasattr(psycopg2._psycopg, 'MXDATETIME'):
|
||||||
del mxDateTimeTests
|
del mxDateTimeTests
|
||||||
|
|
||||||
|
|
||||||
class TimestampFromTicksTestCase(unittest.TestCase):
|
class FromTicksTestCase(unittest.TestCase):
|
||||||
# bug "TimestampFromTicks() throws ValueError (2-2.0.14)"
|
# bug "TimestampFromTicks() throws ValueError (2-2.0.14)"
|
||||||
# reported by Jozsef Szalay on 2010-05-06
|
# 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
|
from datetime import datetime
|
||||||
s = psycopg2.TimestampFromTicks(1273173119.99992)
|
s = psycopg2.TimestampFromTicks(1273173119.99992)
|
||||||
self.assertEqual(s.adapted,
|
self.assertEqual(s.adapted,
|
||||||
datetime(2010, 5, 6, 14, 11, 59, 999920,
|
datetime(2010, 5, 6, 14, 11, 59, 999920,
|
||||||
tzinfo=FixedOffsetTimezone(-5 * 60)))
|
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():
|
def test_suite():
|
||||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user