From 67742073947efe60b103b2ebd07217d2a1c67e9d Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Sun, 21 Nov 2010 15:08:53 +0000 Subject: [PATCH] Fixed #14453 -- Changed handling of microseconds part in typecast_timestamp() DB backend helper function to be more correct. Thanks philipn for the report and fix. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14664 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/util.py | 2 +- tests/regressiontests/db_typecasts/tests.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/django/db/backends/util.py b/django/db/backends/util.py index 865508a057ee4..3ed18adb37400 100644 --- a/django/db/backends/util.py +++ b/django/db/backends/util.py @@ -92,7 +92,7 @@ def typecast_timestamp(s): # does NOT store time zone information else: microseconds = '0' return datetime.datetime(int(dates[0]), int(dates[1]), int(dates[2]), - int(times[0]), int(times[1]), int(seconds), int(float('.'+microseconds) * 1000000)) + int(times[0]), int(times[1]), int(seconds), int((microseconds + '000000')[:6])) def typecast_boolean(s): if s is None: return None diff --git a/tests/regressiontests/db_typecasts/tests.py b/tests/regressiontests/db_typecasts/tests.py index f4b77fe3a6a2a..8c71c8f809695 100644 --- a/tests/regressiontests/db_typecasts/tests.py +++ b/tests/regressiontests/db_typecasts/tests.py @@ -35,6 +35,12 @@ ('2005-08-11 8:50:30.9', datetime.datetime(2005, 8, 11, 8, 50, 30, 900000)), ('2005-08-11 8:50:30.312-05', datetime.datetime(2005, 8, 11, 8, 50, 30, 312000)), ('2005-08-11 8:50:30.312+02', datetime.datetime(2005, 8, 11, 8, 50, 30, 312000)), + # ticket 14453 + ('2010-10-12 15:29:22.063202', datetime.datetime(2010, 10, 12, 15, 29, 22, 63202)), + ('2010-10-12 15:29:22.063202-03', datetime.datetime(2010, 10, 12, 15, 29, 22, 63202)), + ('2010-10-12 15:29:22.063202+04', datetime.datetime(2010, 10, 12, 15, 29, 22, 63202)), + ('2010-10-12 15:29:22.0632021', datetime.datetime(2010, 10, 12, 15, 29, 22, 63202)), + ('2010-10-12 15:29:22.0632029', datetime.datetime(2010, 10, 12, 15, 29, 22, 63202)), ), 'typecast_boolean': ( (None, None), @@ -53,4 +59,4 @@ def test_typeCasts(self): assert got == expected, "In %s: %r doesn't match %r. Got %r instead." % (k, inpt, expected, got) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()