def string_to_datetime(model, fieldname, value):
 if (value is None):
  return value
 field_type = get_field_type(model, fieldname)
 if isinstance(field_type, (Date, Time, DateTime)):
  if (value.strip() == ''):
   return None
  if (value in CURRENT_TIME_MARKERS):
   return getattr(func, value.lower())()
  value_as_datetime = parse_datetime(value)
  if isinstance(field_type, Date):
   return value_as_datetime.date()
  if isinstance(field_type, Time):
   return value_as_datetime.timetz()
  return value_as_datetime
 if (isinstance(field_type, Interval) and isinstance(value, int)):
  return datetime.timedelta(seconds=value)
 return value

def string_to_datetime ( model , fieldname , value ) : if ( value is None ) : return value field_type = get_field_type ( model , fieldname ) if isinstance ( field_type , ( Date , Time , DateTime ) ) : if ( value . strip ( ) == '' ) : return None if ( value in CURRENT_TIME_MARKERS ) : return getattr ( func , value . lower ( ) ) ( ) value_as_datetime = parse_datetime ( value ) if isinstance ( field_type , Date ) : return value_as_datetime . date ( ) if isinstance ( field_type , Time ) : return value_as_datetime . timetz ( ) return value_as_datetime if ( isinstance ( field_type , Interval ) and isinstance ( value , int ) ) : return datetime . timedelta ( seconds = value ) return value
casts value to a :class:datetime .