I am creating a script for a client of mine, that has a charge of "x" from 5:00 the morning until 24:00 the night. Then from 12:00 to 5:00 the morning, the charge is "y".
Let's say, the charges are the following:
05:00 to 24:00 -> 1.00 $
24:00 to 05:00 -> 2.00 $
and a client buy a service at 23:00. The purchased service require two hours to be completed, so I like to change the charge for the expensive period like that:
The service is total 2 Hours long, and it starts at 23:00, so the charge must be as following:
23:00 to 24:00 = 1 Hour x 1.00 $
24:00 to 01:00 = 1 Hour x 2.00 $
Total : 3.00 $
Also the clients are able to set the start time manualy of the service manualy, at the time of purchase.
The question is, how can I calculate the time in the low cost period and the time in the expensive time period ?
Any idea will be highly appreciated :)
PN: Also must be considered the case that a client get a service at 23:00 and the service will finish at the 06:00. That means that the client must be charged for 2 hours in low cost and 5 hours in high rate.
Kind regards Merianos Nikos