git-svn-id: http://code.djangoproject.com/svn/django/trunk@346 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5bfab1e1b2
commit
017b8753a6
|
@ -9,16 +9,20 @@ def typecast_date(s):
|
||||||
|
|
||||||
def typecast_time(s): # does NOT store time zone information
|
def typecast_time(s): # does NOT store time zone information
|
||||||
if not s: return None
|
if not s: return None
|
||||||
bits = s.split(':')
|
hour, minutes, seconds = s.split(':')
|
||||||
if len(bits[2].split('.')) > 1: # if there is a decimal (e.g. '11:16:36.181305')
|
if '.' in seconds: # check whether seconds have a fractional part
|
||||||
return datetime.time(int(bits[0]), int(bits[1]), int(bits[2].split('.')[0]),
|
seconds, microseconds = seconds.split('.')
|
||||||
int(bits[2].split('.')[1].split('-')[0]))
|
else:
|
||||||
else: # no decimal was found (e.g. '12:30:00')
|
microseconds = '0'
|
||||||
return datetime.time(int(bits[0]), int(bits[1]), int(bits[2].split('.')[0]), 0)
|
return datetime.time(int(hour), int(minutes), int(seconds), int(microseconds))
|
||||||
|
|
||||||
def typecast_timestamp(s): # does NOT store time zone information
|
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 s: return None
|
||||||
d, t = s.split()
|
d, t = s.split()
|
||||||
|
if t[-3] in ('-', '+'):
|
||||||
|
t = t[:-3] # Remove the time-zone information, if it exists.
|
||||||
dates = d.split('-')
|
dates = d.split('-')
|
||||||
times = t.split(':')
|
times = t.split(':')
|
||||||
seconds = times[2]
|
seconds = times[2]
|
||||||
|
@ -27,8 +31,7 @@ def typecast_timestamp(s): # does NOT store time zone information
|
||||||
else:
|
else:
|
||||||
microseconds = '0'
|
microseconds = '0'
|
||||||
return datetime.datetime(int(dates[0]), int(dates[1]), int(dates[2]),
|
return datetime.datetime(int(dates[0]), int(dates[1]), int(dates[2]),
|
||||||
int(times[0]), int(times[1]), int(seconds.split('-')[0]),
|
int(times[0]), int(times[1]), int(seconds), int(microseconds))
|
||||||
int(microseconds.split('-')[0]))
|
|
||||||
|
|
||||||
def typecast_boolean(s):
|
def typecast_boolean(s):
|
||||||
if s is None: return None
|
if s is None: return None
|
||||||
|
|
Loading…
Reference in New Issue