Skip to content

Commit

Permalink
[1.2.X] Fixed #14453 -- Changed handling of microseconds part in type…
Browse files Browse the repository at this point in the history
…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
ramiro committed Nov 21, 2010
1 parent 99bad1b commit 4e3c8c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django/db/backends/util.py
Expand Up @@ -81,7 +81,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
Expand Down
8 changes: 7 additions & 1 deletion tests/regressiontests/db_typecasts/tests.py
Expand Up @@ -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),
Expand All @@ -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()
unittest.main()

0 comments on commit 4e3c8c6

Please sign in to comment.