def time_check()

in metrics/heron/tmaster/client.py [0:0]


def time_check(start: dt.datetime, end: dt.datetime,
               time_limit_hrs: float) -> None:
    """ Checks the time period, defined by the supplied start and end points,
    against the period defined from now back by the supplied time limit in
    hours. If the time check passes then nothing will be returned.

    Arguments:
        start (datetime):    The start of the time period. Should be UTC.
        end (datetime):  The end of the time period. Should be UTC.
        time_limit_hrs (float): The number of hours back from now that define
                                the allowed time period.

    Raises:
        RuntimeError:   If the supplied time period is not within the defined
                        limit or if the end time is before the start time.
        RuntimeWarning: If the supplied time period crosses the limits of the
                        metrics storage period.
    """

    if end < start:
        msg: str = (f"The supplied end time ({end.isoformat}) is before the "
                    f"supplied start time ({start.isoformat}). No data will "
                    f"be returned.")
        LOG.error(msg)
        raise RuntimeError(msg)

    now: dt.datetime = dt.datetime.now(dt.timezone.utc)
    limit: dt.datetime = now - dt.timedelta(hours=time_limit_hrs)

    if start < limit and end < limit:
        limit_msg: str = (f"The defined time period ({start.isoformat()} to "
                          f"{end.isoformat()}) is outside of the "
                          f"{time_limit_hrs} hours of data stored by the "
                          f"Topology Master. No data will be returned.")
        LOG.error(limit_msg)
        raise RuntimeError(limit_msg)

    if start < limit and end > limit:
        truncated_duration: float = round(((end - limit).total_seconds() /
                                           3600), 2)
        truncated_msg: str = (f"The start ({start.isoformat()}) of the "
                              f"supplied time window is beyond the "
                              f"{time_limit_hrs} hours stored by the Topology "
                              f"Master. Results will be limited to "
                              f"{truncated_duration} hours from "
                              f"{limit.isoformat()} to {end.isoformat()}")
        LOG.warning(truncated_msg)
        warnings.warn(truncated_msg, RuntimeWarning)