def get_datetime(timestamp):
    """
        Turn a string timestamp into a date time. First tries to use dateutil.
        Failing that it tries to guess the time format and converts it manually
        using stfptime.

        @returns: A timezone unaware timestamp.
    """
    timestamp_is_float = False
    try:
        float(timestamp)
        timestamp_is_float = True
    except (ValueError, TypeError):
        pass

    if timestamp_is_float == True:
        raise ValueError("Timestamp %s is a float"%(timestamp,))

    #First try to use date util. Failing that, continue
    try:
        parsed_dt = parse(timestamp, dayfirst=False)
        if parsed_dt.tzinfo is None:
            return parsed_dt
        else:

            return parsed_dt.replace(tzinfo=None)
    except:
        pass

    if isinstance(timestamp, datetime):
        return timestamp

    fmt = guess_timefmt(timestamp)
    if fmt is None:
        fmt = FORMAT

    # and proceed as usual
    try:
        ts_time = datetime.strptime(timestamp, fmt)
    except ValueError as e:
        if e.message.split(' ', 1)[0].strip() == 'unconverted':
            utcoffset = e.message.split()[3].strip()
            timestamp = timestamp.replace(utcoffset, '')
            ts_time = datetime.strptime(timestamp, fmt)
            # Apply offset
            tzoffset = timedelta(hours=int(utcoffset[0:3]),
                                          minutes=int(utcoffset[3:5]))
            ts_time -= tzoffset
        else:
            raise e

    return ts_time
def get_datetime ( timestamp ) : timestamp_is_float = False try : float ( timestamp ) timestamp_is_float = True except ( ValueError , TypeError ) : pass if timestamp_is_float == True : raise ValueError ( "Timestamp %s is a float" % ( timestamp , ) ) try : parsed_dt = parse ( timestamp , dayfirst = False ) if parsed_dt . tzinfo is None : return parsed_dt else : return parsed_dt . replace ( tzinfo = None ) except : pass if isinstance ( timestamp , datetime ) : return timestamp fmt = guess_timefmt ( timestamp ) if fmt is None : fmt = FORMAT try : ts_time = datetime . strptime ( timestamp , fmt ) except ValueError as e : if e . message . split ( ' ' , 1 ) [ 0 ] . strip ( ) == 'unconverted' : utcoffset = e . message . split ( ) [ 3 ] . strip ( ) timestamp = timestamp . replace ( utcoffset , '' ) ts_time = datetime . strptime ( timestamp , fmt ) tzoffset = timedelta ( hours = int ( utcoffset [ 0 : 3 ] ) , minutes = int ( utcoffset [ 3 : 5 ] ) ) ts_time -= tzoffset else : raise e return ts_time
Turn a string timestamp into a date time. First tries to use dateutil.
        Failing that it tries to guess the time format and converts it manually
        using stfptime.

        @returns: A timezone unaware timestamp.