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
|
||||
if not s: return None
|
||||
bits = s.split(':')
|
||||
if len(bits[2].split('.')) > 1: # if there is a decimal (e.g. '11:16:36.181305')
|
||||
return datetime.time(int(bits[0]), int(bits[1]), int(bits[2].split('.')[0]),
|
||||
int(bits[2].split('.')[1].split('-')[0]))
|
||||
else: # no decimal was found (e.g. '12:30:00')
|
||||
return datetime.time(int(bits[0]), int(bits[1]), int(bits[2].split('.')[0]), 0)
|
||||
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(microseconds))
|
||||
|
||||
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
|
||||
d, t = s.split()
|
||||
if t[-3] in ('-', '+'):
|
||||
t = t[:-3] # Remove the time-zone information, if it exists.
|
||||
dates = d.split('-')
|
||||
times = t.split(':')
|
||||
seconds = times[2]
|
||||
|
@ -27,8 +31,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.split('-')[0]),
|
||||
int(microseconds.split('-')[0]))
|
||||
int(times[0]), int(times[1]), int(seconds), int(microseconds))
|
||||
|
||||
def typecast_boolean(s):
|
||||
if s is None: return None
|
||||
|
|
Loading…
Reference in New Issue