use super::funejson::Value; use super::math_round_div::round_div; /// 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. /// /// # Panics /// Panics on negative minutes, an increment below one, or an unknown mode. pub fn round_to_increment(minutes: i64, increment: i64, mode: &str) -> i64 { if minutes < 0 { panic!("minutes must be a non-negative integer, received {}", minutes); } if increment < 1 { panic!("increment must be a positive integer, received {}", increment); } round_div(minutes, increment, mode) * increment } pub fn fune_vector(args: &[Value]) -> Value { Value::Int(round_to_increment( args[0].as_i64(), args[1].as_i64(), args[2].as_str(), )) }