from datetime import datetime


def _slurm_time_trans(timestr, _format="%Y-%m-%dT%H:%M:%S"):
    """
    Fault tolerant time string translate to time obj and time stamps

    :param timestr: str.
    :param _format: Optional[str]. Default as "%Y-%m-%dT%H:%M:%S" used in sacct output
    :return: Tuple[Datetime, float]. Datetime obj and timestamp.
    """
    try:
        timeob = datetime.strptime(timestr, _format)
        timets = timeob.timestamp()
    except ValueError:
        timeob = timestr
        timets = timeob
    return timeob, timets