summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-06-07 17:04:14 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2011-06-08 15:05:15 -0300
commita698807fd0cbc3b0c392375bb8d78218cb4adece (patch)
tree7e7d002618467766bc632c181c1242ed76dba0a6
parente48aa921039e608bbe1dea0adfeb381be87a29df (diff)
downloadpyside-a698807fd0cbc3b0c392375bb8d78218cb4adece.tar.gz
pyside-a698807fd0cbc3b0c392375bb8d78218cb4adece.tar.xz
pyside-a698807fd0cbc3b0c392375bb8d78218cb4adece.zip
Fix bug 869 - "QDateTimeEdit initial time problem"
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Marcelo Lira <marcelo.lira@openbossa.org>
-rw-r--r--PySide/QtCore/qdatetime_conversions.h4
-rw-r--r--PySide/QtCore/qtime_conversions.h4
-rw-r--r--PySide/QtCore/typesystem_core.xml4
-rw-r--r--tests/QtCore/python_conversion.py8
-rw-r--r--tests/QtCore/qdatetime_test.py9
5 files changed, 17 insertions, 12 deletions
diff --git a/PySide/QtCore/qdatetime_conversions.h b/PySide/QtCore/qdatetime_conversions.h
index 8ee4f48..38c0336 100644
--- a/PySide/QtCore/qdatetime_conversions.h
+++ b/PySide/QtCore/qdatetime_conversions.h
@@ -39,8 +39,8 @@ inline QDateTime Converter<QDateTime>::toCpp(PyObject* pyObj)
int hour = PyDateTime_DATE_GET_HOUR(pyObj);
int min = PyDateTime_DATE_GET_MINUTE(pyObj);
int sec = PyDateTime_DATE_GET_SECOND(pyObj);
- int msec = PyDateTime_DATE_GET_MICROSECOND(pyObj);
- return QDateTime(QDate(year, month, day), QTime(hour, min, sec, msec));
+ int usec = PyDateTime_DATE_GET_MICROSECOND(pyObj);
+ return QDateTime(QDate(year, month, day), QTime(hour, min, sec, usec/1000));
} else {
return ValueTypeConverter<QDateTime>::toCpp(pyObj);
}
diff --git a/PySide/QtCore/qtime_conversions.h b/PySide/QtCore/qtime_conversions.h
index 080df5f..4600ef7 100644
--- a/PySide/QtCore/qtime_conversions.h
+++ b/PySide/QtCore/qtime_conversions.h
@@ -35,8 +35,8 @@ inline QTime Converter<QTime>::toCpp(PyObject* pyObj)
int hour = PyDateTime_TIME_GET_HOUR(pyObj);
int min = PyDateTime_TIME_GET_MINUTE(pyObj);
int sec = PyDateTime_TIME_GET_SECOND(pyObj);
- int msec = PyDateTime_TIME_GET_MICROSECOND(pyObj);
- return QTime(hour, min, sec, msec);
+ int usec = PyDateTime_TIME_GET_MICROSECOND(pyObj);
+ return QTime(hour, min, sec, usec/1000);
} else {
return ValueTypeConverter<QTime>::toCpp(pyObj);
}
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index ec79450..3007c80 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -661,7 +661,7 @@
QDate date = %CPPSELF.date();
QTime time = %CPPSELF.time();
if (!PyDateTimeAPI) PyDateTime_IMPORT;
- %PYARG_0 = PyDateTime_FromDateAndTime(date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second(), time.msec());
+ %PYARG_0 = PyDateTime_FromDateAndTime(date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second(), time.msec()*1000);
</inject-code>
</add-function>
</value-type>
@@ -986,7 +986,7 @@
<add-function signature="toPython()" return-type="PyObject">
<inject-code class="target" position="beginning">
if (!PyDateTimeAPI) PyDateTime_IMPORT;
- %PYARG_0 = PyTime_FromTime(%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec());
+ %PYARG_0 = PyTime_FromTime(%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec()*1000);
</inject-code>
</add-function>
</value-type>
diff --git a/tests/QtCore/python_conversion.py b/tests/QtCore/python_conversion.py
index b75fee1..f6fadad 100644
--- a/tests/QtCore/python_conversion.py
+++ b/tests/QtCore/python_conversion.py
@@ -18,17 +18,17 @@ class TestDateTimeConversions (unittest.TestCase):
self.assertEqual(date, other.toPython())
def testQTime(self):
- time = datetime.time(11, 14, 00, 01)
+ time = datetime.time(11, 14, 00, 1000)
other = QTime(time)
self.assertEqual(time.hour, other.hour())
self.assertEqual(time.minute, other.minute())
self.assertEqual(time.second, other.second())
- self.assertEqual(time.microsecond, other.msec())
+ self.assertEqual(time.microsecond/1000, other.msec())
self.assertEqual(time, other.toPython())
def testQDateTime(self):
- dateTime = datetime.datetime(2010, 04, 23, 11, 14, 00, 01)
+ dateTime = datetime.datetime(2010, 04, 23, 11, 14, 00, 1000)
other = QDateTime(dateTime)
otherDate = other.date()
@@ -40,7 +40,7 @@ class TestDateTimeConversions (unittest.TestCase):
self.assertEqual(dateTime.hour, otherTime.hour())
self.assertEqual(dateTime.minute, otherTime.minute())
self.assertEqual(dateTime.second, otherTime.second())
- self.assertEqual(dateTime.microsecond, otherTime.msec())
+ self.assertEqual(dateTime.microsecond/1000, otherTime.msec())
self.assertEqual(dateTime, other.toPython())
diff --git a/tests/QtCore/qdatetime_test.py b/tests/QtCore/qdatetime_test.py
index b732477..ebc9dfb 100644
--- a/tests/QtCore/qdatetime_test.py
+++ b/tests/QtCore/qdatetime_test.py
@@ -6,13 +6,18 @@ from PySide.QtCore import QDateTime, QDate, QTime
class TestQDate (unittest.TestCase):
def testDateConversion(self):
dateTime = QDateTime(QDate(2011, 05, 17), QTime(11, 01, 14, 15))
- dateTimePy = QDateTime(datetime.date(2011, 05, 17), datetime.time(11, 01, 14, 15))
+ dateTimePy = QDateTime(datetime.date(2011, 05, 17), datetime.time(11, 01, 14, 15000))
self.assertEqual(dateTime, dateTimePy)
def testDateTimeConversion(self):
dateTime = QDateTime(QDate(2011, 05, 17), QTime(11, 01, 14, 15))
- dateTimePy = QDateTime(datetime.datetime(2011, 05, 17, 11, 01, 14, 15))
+ dateTimePy = QDateTime(datetime.datetime(2011, 05, 17, 11, 01, 14, 15000))
self.assertEqual(dateTime, dateTimePy)
+ def testDateTimeNow(self):
+ py = datetime.datetime.now()
+ qt = QDateTime(py)
+ self.assertEqual(qt, py)
+
if __name__ == '__main__':
unittest.main()