diff options
Diffstat (limited to 'django/db/backends/util.py')
| -rw-r--r-- | django/db/backends/util.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/django/db/backends/util.py b/django/db/backends/util.py index aa2601277a..f8157c50e7 100644 --- a/django/db/backends/util.py +++ b/django/db/backends/util.py @@ -85,20 +85,25 @@ class CursorDebugWrapper(CursorWrapper): def typecast_date(s): return datetime.date(*map(int, s.split('-'))) if s else None # returns None if s is null + def typecast_time(s): # does NOT store time zone information - if not s: return None + if not s: + return None hour, minutes, seconds = s.split(':') if '.' in seconds: # check whether seconds have a fractional part seconds, microseconds = seconds.split('.') else: microseconds = '0' - return datetime.time(int(hour), int(minutes), int(seconds), int(float('.'+microseconds) * 1000000)) + 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" # "2005-07-29 09:56:00-05" - if not s: return None - if not ' ' in s: return typecast_date(s) + if not s: + return None + if not ' ' in s: + return typecast_date(s) d, t = s.split() # Extract timezone information, if it exists. Currently we just throw # it away, but in the future we may make use of it. @@ -122,11 +127,13 @@ def typecast_timestamp(s): # does NOT store time zone information int(times[0]), int(times[1]), int(seconds), int((microseconds + '000000')[:6]), tzinfo) + def typecast_decimal(s): if s is None or s == '': return None return decimal.Decimal(s) + ############################################### # Converters from Python to database (string) # ############################################### @@ -136,6 +143,7 @@ def rev_typecast_decimal(d): return None return str(d) + def truncate_name(name, length=None, hash_len=4): """Shortens a string to a repeatable mangled version with the given length. """ @@ -143,7 +151,8 @@ def truncate_name(name, length=None, hash_len=4): return name hsh = hashlib.md5(force_bytes(name)).hexdigest()[:hash_len] - return '%s%s' % (name[:length-hash_len], hsh) + return '%s%s' % (name[:length - hash_len], hsh) + def format_number(value, max_digits, decimal_places): """ |
