<think>
Okay, I need to implement the time_gap function. Let's see. The function takes two times, each as hour and minute on a 24-hour clock. The goal is to calculate the minutes from the first time to the second, considering that the second time might be on the next day if it's not later than the first.

First, I need to understand how to calculate the time difference. Let's think about converting both times into total minutes since midnight. For the 'from' time, that's straightforward: from_hour * 60 + from_minute. For the 'to' time, it's to_hour * 60 + to_minute. But since the to time could be the next day, if the to time is earlier than the from time, we need to add 24*60 minutes to it.

Wait, right. So, for example, if from is 23:00 and to is 00:30, the difference is 30 minutes. But if from is 00:00 and to is 23:59, then the difference is 23*60 +59 = 1439 minutes. But if to is 00:00, then it's 24*60 = 1440 minutes.

So the approach is: calculate the total minutes for from and to. If to is less than from, add 24*60 to to. Then subtract from from to get the difference.

But wait, how do I check if to is earlier than from? Let's think. Let's convert both to total minutes. If to_total < from_total, then we add 24*60 to to_total. Then the difference is to_total - from_total. But wait, no. Because if to is on the next day, then the actual time is to_total + 24*60. Then the difference is (to_total + 24*60) - from_total. But that's only if to is earlier than from.

Wait, let me think again. Suppose from is 22:00 (22*60=1320) and to is 00:30 (30). Since 30 < 1320, the to is on the next day. So the difference is 30 + 24*60 - 1320 = 30 + 1440 - 1320 = 150 minutes. Which is correct, because 22:00 to midnight is 2 hours (120 min), then midnight to 00:30 is 30 min, total 150.

So the formula is: calculate from_total and to_total. If to_total is less than from_total, then add 24*60 to to_total. Then the difference is to_total - from_total.

But wait, what if the to is exactly the same as from? Then the difference is zero. But according to the problem statement, the to is considered to be on the following day if it's not later. So if to is same as from, then it's zero. But in that case, the to is not later, so we add 24*60, but then subtract from_total, which would be 24*60 - from_total, which is 1440 - from_total. But that's not correct. Wait, no. Let me think again.

Wait, if from is 12:00 (720) and to is 12: