def METHOD_NAME(
    self, time_range_constraint: TimeRangeConstraint, time_granularity: TimeGranularity
) -> TimeRangeConstraint:
    """Change the time range so that the ends are at the ends of the appropriate time granularity windows.
    e.g. [2020-01-15, 2020-2-15] with MONTH granularity -> [2020-01-01, 2020-02-29]
    """
    constraint_start = time_range_constraint.start_time
    constraint_end = time_range_constraint.end_time
    start_ts = pd.Timestamp(time_range_constraint.start_time)
    if not is_period_start(time_granularity, start_ts):
        constraint_start = adjust_to_start_of_period(time_granularity, start_ts).to_pydatetime()
    end_ts = pd.Timestamp(time_range_constraint.end_time)
    if not is_period_end(time_granularity, end_ts):
        constraint_end = adjust_to_end_of_period(time_granularity, end_ts).to_pydatetime()
    if constraint_start < TimeRangeConstraint.ALL_TIME_BEGIN():
        constraint_start = TimeRangeConstraint.ALL_TIME_BEGIN()
    if constraint_end > TimeRangeConstraint.ALL_TIME_END():
        constraint_end = TimeRangeConstraint.ALL_TIME_END()
    return TimeRangeConstraint(start_time=constraint_start, end_time=constraint_end)