So far I just wrote asked user to input the starting time of call and length of the call.
let says that user input (enter) the starting time is at 4:00 pm and the call least for 7 hours...
since it is start at 4:00 pm and goes to 5:00 pm. In that time the rate of the calling is .15 and since doesn't stop at 5:00 pm, So remainder 3 hours should be at 6-9 hours and In that time the rate is .20.
is here the equation I come up:
(1*.15) <----- for the 1 hour.
(3*.20) <----- for remainder hours.
It seems by your example that "calls" are "whole hours". Calls starting 1pm, 2pm, 3pm, or 4pm should charge .15 per hour and calls starting at 6pm, 7pm, or 8pm charge .2 per hour.
Now, your example call starts 4pm and could be split to 7 one hour calls. The first is .15. The second from 5pm to 6pm is apparently free. Then, the next three from 6pm to 9pm charge .2 each, and the last two are again free.
You have the starting time and duration.
If it is less than 1pm, you decrease the difference from the duration.
If there is any duration left, then you take the minimum of duration and .15 period and use that to charge with .15. Reduce the time from duration.
If any duration is left, do similar step with the .2 period.
Actually, if the duration goes around the clock, you should at start take as many days off the duration as possible (a division&modulus) and add their charge.