Created
December 7, 2015 03:45
-
-
Save Nalisarc/261fc250416356b44892 to your computer and use it in GitHub Desktop.
Parkingcall
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timecal(entryTime, exitTime){ | |
var enh = entryTime.slice(0,2); | |
var enm = entryTime.slice(3); | |
var exh = exitTime.slice(0,2); | |
var exm = exitTime.slice(3); | |
var en = new Date(2000, 0, 1,enh,enm); | |
var ex = new Date(2000, 0, 1,exh,exm); | |
if (ex < en){ | |
ex.setDate(ex.getDate() + 1); | |
} | |
var dif = ex - en; | |
var msec = dif; | |
var m = Math.floor(msec / 1000 / 60); | |
return m; | |
} | |
function basecal(minutes){ | |
var cost = 0; // sets cost as 0 | |
if(minutes <= 15){ //* if minutes is less that 16 cost is 0 *// | |
return cost; | |
} | |
else{ // Because minutes is greater than 15 cost is 1 | |
cost += 1; | |
} | |
if(minutes <= 30){ //* Cost is 1 but if minutes is less than 31 cost is 1 *// | |
return cost; | |
} | |
else{ //* cost is 3 because minutes is greater than 30 *// | |
cost += 2; | |
} | |
// checks if minutes is greater than 60 | |
if(minutes > 60){ | |
//* if minutes is greater than 60 minutes is divided by 30*// | |
for(var i = 0; i < (minutes / 30); i++){ | |
// for every 30 minutes after 60 cost is increased by 1 | |
cost += 1; | |
} | |
return cost; | |
} | |
else{ | |
return cost; | |
} | |
} | |
function valcal(val,cost){ | |
// if you have validations this takes the amount and subtracks that amount off of your cost. | |
if(val > 0){ | |
var re = cost - (val * 2) + 1; | |
if(re < 0){ | |
re = 0; | |
return re; | |
} | |
} | |
else{ | |
return cost; | |
} | |
} | |
function alldaycal(allval,cost){ | |
if(allval === true){ | |
var re = cost - 20; | |
if(re < 0){ | |
re = 0; | |
return re; | |
} | |
} | |
else{ | |
return cost; | |
} | |
} | |
function calc(entryTime,exitTime,val,allval){ | |
var min = timecal(entryTime,exitTime); | |
// takes entryTime and exitTime to get the minutes in the lot | |
var cost = basecal(min); | |
// checks for validations and evaluates them | |
if(val > 0){ | |
cost = valcal(val,basecost); | |
} | |
// checks for allday validations and evaluates | |
if(allval === true){ | |
cost = alldaycal(allval,cost); | |
} | |
// checks if entry time was 18:00 or later | |
if(parseInt(entryTime.slice(0,2)) >= 18){ | |
if(cost > 5){ | |
// if so maxs price at 5 | |
cost = 5; | |
} | |
} | |
// caps cost at 20 | |
if(cost > 20){ | |
cost = 20; | |
} | |
// returns cost | |
return cost; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Parking Calculator</title> | |
<noscript> You need Javascript for this to work! </noscript> | |
</head> | |
<body> | |
Entry Time: (HH:MM)<br> | |
<input type="text" name="entryTime"> | |
<br> | |
Exit Time: (HH:MM)<br> | |
<input type="text" name="exitTime"</input> | |
<br> | |
<br> | |
Validations: <input type="number" name="val" min="0" max="10" value="0"> <br> | |
<br> | |
Allday Validation: <input type="checkbox" name="allval" value="av"><br> | |
<br> | |
<input type="submit"</input> | |
<br> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment