Skip to content

Instantly share code, notes, and snippets.

@SarahSexton
Last active May 13, 2023 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SarahSexton/37b57a1e161099cb68e9f5e2e5950d93 to your computer and use it in GitHub Desktop.
Save SarahSexton/37b57a1e161099cb68e9f5e2e5950d93 to your computer and use it in GitHub Desktop.
A web-based "Airport Estimations" form that estimates various times related to the airport journey. If you're trying to catch a flight, you can put in your information. It calculates the estimated time your flight starts boarding, walking to your gate, and when to leave your home/start your journey. Ensure you're packed on time with these results!
<!DOCTYPE html>
<html>
<head>
<title>Airport Estimations</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
label {
font-weight: bold;
display: block;
margin-top: 10px;
}
input[type="text"] {
width: 200px;
padding: 5px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
font-weight: bold;
}
</style>
<script>
var convertTo12HourCalled = false;
function formatTime(date) {
var hours = date.getHours().toString().padStart(2, '0');
var minutes = date.getMinutes().toString().padStart(2, '0');
return hours + ':' + minutes;
}
function convertTo12Hour() {
var input = document.getElementById('hourInput').value;
var hour = parseInt(input);
if (hour >= 1 && hour <= 12) {
var convertedHour = (hour + 12) % 24;
document.getElementById('convertedTime').innerHTML = 'Converted Time: ' + convertedHour;
} else {
document.getElementById('convertedTime').innerHTML = 'Invalid input. Please enter a number between 1 and 12.';
}
convertTo12HourCalled = true;
}
function calculateTimes() {
var departureTime = document.getElementById('departureTime').value;
var securityWait = parseInt(document.getElementById('securityWait').value);
var commuteTime = parseInt(document.getElementById('commuteTime').value);
var departTime = new Date('01/01/2000 ' + departureTime);
var boardingTime = new Date(departTime - 30 * 60000);
var walkToGateTime = new Date(boardingTime - 10 * 60000);
var finishTSATime = new Date(walkToGateTime - 10 * 60000);
var securityTime = new Date(finishTSATime - securityWait * 60000);
var commuteToAirportTime = new Date(securityTime - commuteTime * 60000);
var leaveHouseTime = new Date(commuteToAirportTime - 15 * 60000);
var dressedAndPackedTime = new Date(leaveHouseTime - 60 * 60000);
var resultElement = document.getElementById('result');
resultElement.innerHTML = ''; // Clear previous results
var displayResult = function (label, time) {
var formattedTime = time.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
var paragraph = document.createElement('p');
paragraph.innerText = label + ': ' + formattedTime;
resultElement.appendChild(paragraph);
};
displayResult('Depart', departTime);
displayResult('Boarding', boardingTime);
displayResult('Walk to Gate', walkToGateTime);
displayResult('Finish TSA', finishTSATime);
displayResult('Security Time', securityTime);
displayResult('Commute to Airport Time', commuteToAirportTime);
displayResult('Leave House Time', leaveHouseTime);
displayResult('Dressed and Packed Time', dressedAndPackedTime);
if (convertTo12HourCalled) {
function meridiemMath () {
var times = resultElement.querySelectorAll('p');
times.forEach(function (time) {
var timeValue = time.innerText;
var hour = parseInt(timeValue.split(':')[1].trim().split(' ')[0]);
var period = (hour >= 12) ? 'PM' : 'AM';
var convertedHour = (hour % 12) || 12;
time.innerText = timeValue.replace(hour, convertedHour + ' ' + period);
});
resultElement.removeChild(convertButton);
};
}
}
</script>
</body>
</head>
<body>
<h1>Airport Estimations</h1>
<!-- 24-hour to 12-hour Converter section -->
<div>
<h2>24-hour to 12-hour Converter</h2>
<label for="hourInput">Enter an hour (1-12):</label>
<input type="text" id="hourInput">
<button onclick="convertTo12Hour()">Convert</button>
<p id="convertedTime"></p>
</div>
<div>
<h2>Airport Estimation Calculator</h2>
<form>
<label for="departureTime">Departure Time (00:00)</label>
<input type="text" id="departureTime">
<label for="securityWait">Security Wait Times (in minutes)</label>
<input type="text" id="securityWait">
<label for="commuteTime">Commute to Airport (in minutes)</label>
<input type="text" id="commuteTime">
</form>
<button onclick="calculateTimes()">Calculate</button>
<div id="result"></div>
<div id="convertedResult"></div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment