Source code for schrodinger.application.job_monitor.util
from datetime import datetime
from dateutil import tz
TIME_DISPLAY_FORMAT = "%I:%M%p"
DATE_DISPLAY_FORMAT = "%d %b %Y"
[docs]def convert_to_local_timezone(utc_epoch_time):
    """
    Return the local timezone datetime object for the UTC
    epoch time.
    :param utc_epoch_time: UTC epoch time
    :type utc_epoch_time: float
    :rtype: datetime.datetime
    """
    utc_datetime_string = datetime.fromtimestamp(utc_epoch_time).strftime(
        f'{TIME_DISPLAY_FORMAT} {DATE_DISPLAY_FORMAT}')
    utc_datetime = datetime.strptime(
        utc_datetime_string, f'{TIME_DISPLAY_FORMAT} {DATE_DISPLAY_FORMAT}')
    utc_timezone = tz.tzutc()
    # Let the datetime object know it's UTC time
    utc_datetime = utc_datetime.replace(tzinfo=utc_timezone)
    local_timezone = tz.tzlocal()
    # Convert the UTC datetime object to local datetime object
    local_datetime = utc_datetime.astimezone(local_timezone)
    return local_datetime 
[docs]def is_same_day(local_datetime):
    """
    Check whether the local datetime is of the the current day.
    :type local_datetime: datetime.datetime
    :rtype: bool
    """
    return local_datetime.date() == datetime.today().date() 
[docs]def get_current_utc_timestamp():
    """
    Return the UTC current epoch time.
    :rtype: float
    """
    return datetime.utcnow().timestamp()