def parse_datetime(value):
 match = datetime_re.match(value)
 if match:
  kw = match.groupdict()
  if kw['microsecond']:
   kw['microsecond'] = kw['microsecond'].ljust(6, '0')
  tzinfo = kw.pop('tzinfo')
  if (tzinfo == 'Z'):
   tzinfo = utc
  elif (tzinfo is not None):
   offset_mins = (int(tzinfo[(-2):]) if (len(tzinfo) > 3) else 0)
   offset = ((60 * int(tzinfo[1:3])) + offset_mins)
   if (tzinfo[0] == '-'):
    offset = (- offset)
   tzinfo = get_fixed_timezone(offset)
  kw = {k: int(v) for (k, v) in kw.items() if (v is not None)}
  kw['tzinfo'] = tzinfo
  return datetime.datetime(**kw)

def parse_datetime ( value ) : match = datetime_re . match ( value ) if match : kw = match . groupdict ( ) if kw [ 'microsecond' ] : kw [ 'microsecond' ] = kw [ 'microsecond' ] . ljust ( 6 , '0' ) tzinfo = kw . pop ( 'tzinfo' ) if ( tzinfo == 'Z' ) : tzinfo = utc elif ( tzinfo is not None ) : offset_mins = ( int ( tzinfo [ ( - 2 ) : ] ) if ( len ( tzinfo ) > 3 ) else 0 ) offset = ( ( 60 * int ( tzinfo [ 1 : 3 ] ) ) + offset_mins ) if ( tzinfo [ 0 ] == '-' ) : offset = ( - offset ) tzinfo = get_fixed_timezone ( offset ) kw = { k : int ( v ) for ( k , v ) in kw . items ( ) if ( v is not None ) } kw [ 'tzinfo' ] = tzinfo return datetime . datetime ( ** kw )
parses a string and return a datetime .