1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Changed timestamp and time typecasting to preserve microseconds. Added unit tests to test this behavior, and added a db_typecast unit test module. Refs #306.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@487 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty
2005-08-11 19:34:34 +00:00
parent 8ebe5db684
commit 8d8da826db
4 changed files with 92 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ import datetime
###############################################
def typecast_date(s):
return s and datetime.date(*map(int, s.split('-'))) # returns None if s is null
return s and datetime.date(*map(int, s.split('-'))) or None # returns None if s is null
def typecast_time(s): # does NOT store time zone information
if not s: return None
@@ -14,7 +14,7 @@ def typecast_time(s): # does NOT store time zone information
seconds, microseconds = seconds.split('.')
else:
microseconds = '0'
return datetime.time(int(hour), int(minutes), int(seconds), int(microseconds))
return datetime.time(int(hour), int(minutes), int(seconds), int(float('.'+microseconds) * 1000000))
def typecast_timestamp(s): # does NOT store time zone information
# "2005-07-29 15:48:00.590358-05"
@@ -39,10 +39,11 @@ 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(microseconds))
int(times[0]), int(times[1]), int(seconds), int(float('.'+microseconds) * 1000000))
def typecast_boolean(s):
if s is None: return None
if not s: return False
return str(s)[0].lower() == 't'
###############################################

View File

@@ -299,7 +299,7 @@ class DateTimeField(DateField):
def get_db_prep_save(self, value):
# Casts dates into string format for entry into database.
if value is not None:
value = value.strftime('%Y-%m-%d %H:%M:%S')
value = str(value)
return Field.get_db_prep_save(self, value)
def get_manipulator_field_objs(self):
@@ -493,7 +493,7 @@ class TimeField(Field):
def get_db_prep_save(self, value):
# Casts dates into string format for entry into database.
if value is not None:
value = value.strftime('%H:%M:%S')
value = str(value)
return Field.get_db_prep_save(self, value)
def get_manipulator_field_objs(self):