Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #14453 -- Changed handling of microseconds part in type…

…cast_timestamp() DB backend helper function to be more correct. Thanks philipn for the report and fix.

Backport of [14664] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14665 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4e3c8c6aff5d0cb2d3869cae36618da6106d65be 1 parent 99bad1b
Ramiro Morales authored November 21, 2010
2  django/db/backends/util.py
@@ -81,7 +81,7 @@ def typecast_timestamp(s): # does NOT store time zone information
81 81
     else:
82 82
         microseconds = '0'
83 83
     return datetime.datetime(int(dates[0]), int(dates[1]), int(dates[2]),
84  
-        int(times[0]), int(times[1]), int(seconds), int(float('.'+microseconds) * 1000000))
  84
+        int(times[0]), int(times[1]), int(seconds), int((microseconds + '000000')[:6]))
85 85
 
86 86
 def typecast_boolean(s):
87 87
     if s is None: return None
8  tests/regressiontests/db_typecasts/tests.py
@@ -35,6 +35,12 @@
35 35
         ('2005-08-11 8:50:30.9', datetime.datetime(2005, 8, 11, 8, 50, 30, 900000)),
36 36
         ('2005-08-11 8:50:30.312-05', datetime.datetime(2005, 8, 11, 8, 50, 30, 312000)),
37 37
         ('2005-08-11 8:50:30.312+02', datetime.datetime(2005, 8, 11, 8, 50, 30, 312000)),
  38
+        # ticket 14453
  39
+        ('2010-10-12 15:29:22.063202', datetime.datetime(2010, 10, 12, 15, 29, 22, 63202)),
  40
+        ('2010-10-12 15:29:22.063202-03', datetime.datetime(2010, 10, 12, 15, 29, 22, 63202)),
  41
+        ('2010-10-12 15:29:22.063202+04', datetime.datetime(2010, 10, 12, 15, 29, 22, 63202)),
  42
+        ('2010-10-12 15:29:22.0632021', datetime.datetime(2010, 10, 12, 15, 29, 22, 63202)),
  43
+        ('2010-10-12 15:29:22.0632029', datetime.datetime(2010, 10, 12, 15, 29, 22, 63202)),
38 44
     ),
39 45
     'typecast_boolean': (
40 46
         (None, None),
@@ -53,4 +59,4 @@ def test_typeCasts(self):
53 59
                 assert got == expected, "In %s: %r doesn't match %r. Got %r instead." % (k, inpt, expected, got)
54 60
 
55 61
 if __name__ == '__main__':
56  
-    unittest.main()
  62
+    unittest.main()

0 notes on commit 4e3c8c6

Please sign in to comment.
Something went wrong with that request. Please try again.