Django

Code

Changeset 346

Show
Ignore:
Timestamp:
07/29/05 16:10:09 (3 years ago)
Author:
adrian
Message:

Fixed #219 and #188 -- Database timestamp typecast no longer assumes '-' delineates the time zone

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/db/typecasts.py

    r3 r346  
    1010def typecast_time(s): # does NOT store time zone information 
    1111    if not s: return None 
    12     bits = s.split(':') 
    13     if len(bits[2].split('.')) > 1: # if there is a decimal (e.g. '11:16:36.181305') 
    14         return datetime.time(int(bits[0]), int(bits[1]), int(bits[2].split('.')[0]), 
    15             int(bits[2].split('.')[1].split('-')[0])) 
    16     else: # no decimal was found (e.g. '12:30:00') 
    17         return datetime.time(int(bits[0]), int(bits[1]), int(bits[2].split('.')[0]), 0
     12    hour, minutes, seconds = s.split(':') 
     13    if '.' in seconds: # check whether seconds have a fractional part 
     14        seconds, microseconds = seconds.split('.') 
     15    else: 
     16        microseconds = '0' 
     17    return datetime.time(int(hour), int(minutes), int(seconds), int(microseconds)
    1818 
    1919def typecast_timestamp(s): # does NOT store time zone information 
     20    # "2005-07-29 15:48:00.590358-05" 
     21    # "2005-07-29 09:56:00-05" 
    2022    if not s: return None 
    2123    d, t = s.split() 
     24    if t[-3] in ('-', '+'): 
     25        t = t[:-3] # Remove the time-zone information, if it exists. 
    2226    dates = d.split('-') 
    2327    times = t.split(':') 
     
    2832        microseconds = '0' 
    2933    return datetime.datetime(int(dates[0]), int(dates[1]), int(dates[2]), 
    30         int(times[0]), int(times[1]), int(seconds.split('-')[0]), 
    31         int(microseconds.split('-')[0])) 
     34        int(times[0]), int(times[1]), int(seconds), int(microseconds)) 
    3235 
    3336def typecast_boolean(s):