summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Thénault <sylvain.thenault@logilab.fr>2016-05-17 18:24:58 +0200
committerSylvain Thénault <sylvain.thenault@logilab.fr>2016-05-17 18:24:58 +0200
commit4ccfa633c970b8a930d35959828a3de4285cc7b6 (patch)
treee7c5c059abe9771767dfb305a1f3ea8bc9bf18e5
parent4cd44570508eab16274d6adf4515afcc9214a198 (diff)
downloadlogilab-common-4ccfa633c970b8a930d35959828a3de4285cc7b6.tar.gz
Fix regression with datetime2ticks vs date object as argument
we should not get a traceback in this case. Closes #6060938
-rw-r--r--logilab/common/date.py2
-rw-r--r--test/unittest_date.py5
2 files changed, 6 insertions, 1 deletions
diff --git a/logilab/common/date.py b/logilab/common/date.py
index 37e371b..1d13a77 100644
--- a/logilab/common/date.py
+++ b/logilab/common/date.py
@@ -237,7 +237,7 @@ def todatetime(somedate):
return datetime(somedate.year, somedate.month, somedate.day)
def datetime2ticks(somedate):
- return timegm(somedate.timetuple()) * 1000 + int(somedate.microsecond / 1000)
+ return timegm(somedate.timetuple()) * 1000 + int(getattr(somedate, 'microsecond', 0) / 1000)
def ticks2datetime(ticks):
miliseconds, microseconds = divmod(ticks, 1000)
diff --git a/test/unittest_date.py b/test/unittest_date.py
index 22302b0..494c86f 100644
--- a/test/unittest_date.py
+++ b/test/unittest_date.py
@@ -174,6 +174,11 @@ class DateTC(TestCase):
d = d.replace(microsecond=123456)
self.assertEqual(datetime2ticks(d), timestamp * 1000 + 123)
+ def test_datetime2ticks_date_argument(self):
+ d = date(2014, 11, 26)
+ timestamp = timegm(d.timetuple())
+ self.assertEqual(datetime2ticks(d), timestamp * 1000)
+
class MxDateTC(DateTC):
datecls = mxDate