from .math_round_div import round_div from .math_round_div_types import RoundingMode def round_to_increment(minutes: int, increment: int, mode: RoundingMode) -> int: """Round a duration to a whole number of billing increments. The rounding is math.round-div's, so "half-up" here is the same rule as for money. """ if isinstance(minutes, bool) or not isinstance(minutes, int) or minutes < 0: raise ValueError("minutes must be a non-negative integer, received %s" % (minutes,)) if isinstance(increment, bool) or not isinstance(increment, int) or increment < 1: raise ValueError("increment must be a positive integer, received %s" % (increment,)) return round_div(minutes, increment, mode) * increment