I am making a website for a limo service that should provide the price for the service you are requesting beforehand.
The regular service is 1$ a minute. However, all the time from mid-night to 8am, is considered premium and it costs 2$.
Now, here is the complicated part. I need to isolate how much time the client is paying on regular time and on premium, in order to generate the price.
For example. If the service is from 9pm to 2am, the client pays 3 hours at 1$/min and 2 hours at 2$/min.
How to I get the 9pm and 2am, and convert to 180minutes+120minutes?
Btw, I tied tampering with http://code.google.com/p/datejs/. But it just was not working. Is there a smart "math" way of doing this?
Thanks for the help guys :)
So premium time is all in the A.M. it seems and non is all in the P.M. so just subtract whatever time they give that's pm from 12, in your example 12-9 and you get 3hours, then add any hours to 0 for the am, again your example 0+2 which is of course 2 hours. Then times by 60 to get the minutes. Once you have that times each amount by the amount its being charged and add them together. I would have the am/pm be a toggle that sets a variable to true/false for each.
code could look something like this:
//start_time and end_time are objects that have 2 properties, am/pm
//which is a bool and time which is a int
function calc_time(start_time,end_time){
var normal_pay;
var premium_pay;
if(start_time.pm == true){
normal_pay = 12 - start_time.time;
normal_pay = normal_pay * 60;
} else{
normal_pay = 0 + start_time.time;
normal_pay = normal_pay * 60 * 2; //this is premium time the whole night was premium pay
}
if(end_time.am == true){
premium_pay = 0 + end_time.time;
premium_pay = premium_pay * 60 * 2;
} else {
premium_pay = 12 - end_time.time;
premium_pay = premium_pay * 60; //this is normal time the whole night was normal pay
}
return premium_pay + normal_pay;
}
This doesn't solve everything you still have to account for things like minutes, say they want to end at 3:25am but that's not that hard.