From 303d73f1c6c4eca67a2ab0dc03ec5118f6ee6bd4 Mon Sep 17 00:00:00 2001 From: Shay Date: Sun, 11 Jan 2026 17:34:23 +0000 Subject: [PATCH 1/2] Implement Rush Hour time inputs and logic Added a Rush Hour section with AM and PM time inputs and functionality to generate rush hour times. --- fleet/templates/timetable_add.html | 162 ++++++++++++++++++++++++++++- 1 file changed, 160 insertions(+), 2 deletions(-) diff --git a/fleet/templates/timetable_add.html b/fleet/templates/timetable_add.html index 7d70430f..3fc1eea9 100755 --- a/fleet/templates/timetable_add.html +++ b/fleet/templates/timetable_add.html @@ -93,7 +93,59 @@

Generate Departures

- + +
+
+ 3 +

Rush Hour (Optional)

+
+
+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+ +
3 @@ -425,6 +477,112 @@

Timetable Preview

generateStopTimesJSON(); } +function applyRushHours() { + const amStart = document.getElementById("rush-am-start").value; + const amEnd = document.getElementById("rush-am-end").value; + const amInterval = parseInt(document.getElementById("rush-am-interval").value, 10); + + const pmStart = document.getElementById("rush-pm-start").value; + const pmEnd = document.getElementById("rush-pm-end").value; + const pmInterval = parseInt(document.getElementById("rush-pm-interval").value, 10); + + const timesInput = document.querySelector('.departure-times'); + let existingTimes = timesInput.value.split(',').map(t => t.trim()).filter(Boolean); + + // Helper function to generate times for a rush period + function generateRushTimes(start, end, interval) { + if (!start || !end || !interval || interval <= 0) return []; + + const times = []; + let [startHour, startMin] = start.split(":").map(Number); + const [endHour, endMin] = end.split(":").map(Number); + + while (startHour < endHour || (startHour === endHour && startMin <= endMin)) { + times.push(`${String(startHour).padStart(2, "0")}:${String(startMin).padStart(2, "0")}`); + startMin += interval; + if (startMin >= 60) { + startHour += Math.floor(startMin / 60); + startMin = startMin % 60; + } + } + + return times; + } + + // Generate AM rush times + const amTimes = generateRushTimes(amStart, amEnd, amInterval); + + // Generate PM rush times + const pmTimes = generateRushTimes(pmStart, pmEnd, pmInterval); + + // Merge all times and remove duplicates + const allTimes = [...existingTimes, ...amTimes, ...pmTimes]; + + // Sort times and remove duplicates + const uniqueTimes = [...new Set(allTimes)].sort((a, b) => { + const [aH, aM] = a.split(':').map(Number); + const [bH, bM] = b.split(':').map(Number); + return (aH * 60 + aM) - (bH * 60 + bM); + }); + + timesInput.value = uniqueTimes.join(", "); + generateStopTimesJSON(); + + alert(`Added ${amTimes.length} AM rush trips and ${pmTimes.length} PM rush trips.`); +}function applyRushHours() { + const amStart = document.getElementById("rush-am-start").value; + const amEnd = document.getElementById("rush-am-end").value; + const amInterval = parseInt(document.getElementById("rush-am-interval").value, 10); + + const pmStart = document.getElementById("rush-pm-start").value; + const pmEnd = document.getElementById("rush-pm-end").value; + const pmInterval = parseInt(document.getElementById("rush-pm-interval").value, 10); + + const timesInput = document.querySelector('.departure-times'); + let existingTimes = timesInput.value.split(',').map(t => t.trim()).filter(Boolean); + + // Helper function to generate times for a rush period + function generateRushTimes(start, end, interval) { + if (!start || !end || !interval || interval <= 0) return []; + + const times = []; + let [startHour, startMin] = start.split(":").map(Number); + const [endHour, endMin] = end.split(":").map(Number); + + while (startHour < endHour || (startHour === endHour && startMin <= endMin)) { + times.push(`${String(startHour).padStart(2, "0")}:${String(startMin).padStart(2, "0")}`); + startMin += interval; + if (startMin >= 60) { + startHour += Math.floor(startMin / 60); + startMin = startMin % 60; + } + } + + return times; + } + + // Generate AM rush times + const amTimes = generateRushTimes(amStart, amEnd, amInterval); + + // Generate PM rush times + const pmTimes = generateRushTimes(pmStart, pmEnd, pmInterval); + + // Merge all times and remove duplicates + const allTimes = [...existingTimes, ...amTimes, ...pmTimes]; + + // Sort times and remove duplicates + const uniqueTimes = [...new Set(allTimes)].sort((a, b) => { + const [aH, aM] = a.split(':').map(Number); + const [bH, bM] = b.split(':').map(Number); + return (aH * 60 + aM) - (bH * 60 + bM); + }); + + timesInput.value = uniqueTimes.join(", "); + generateStopTimesJSON(); + + alert(`Added ${amTimes.length} AM rush trips and ${pmTimes.length} PM rush trips.`); +} + function autoFillOffsets() { const offset = parseInt(document.getElementById("offset-fill").value, 10); if (isNaN(offset) || offset < 0) { @@ -1358,4 +1516,4 @@

Timetable Preview

align-items: flex-end; } -{% endblock %} \ No newline at end of file +{% endblock %} From 6fd75100885b5cd29082787788f757183f01c31a Mon Sep 17 00:00:00 2001 From: Shay Date: Sun, 11 Jan 2026 17:42:54 +0000 Subject: [PATCH 2/2] Remove duplicate applyRushHours function from timetable_add.html Removed the duplicate applyRushHours function that generated rush hour times based on user inputs. --- fleet/templates/timetable_add.html | 52 ------------------------------ 1 file changed, 52 deletions(-) diff --git a/fleet/templates/timetable_add.html b/fleet/templates/timetable_add.html index 3fc1eea9..428a0bbe 100755 --- a/fleet/templates/timetable_add.html +++ b/fleet/templates/timetable_add.html @@ -528,58 +528,6 @@

Timetable Preview

timesInput.value = uniqueTimes.join(", "); generateStopTimesJSON(); - alert(`Added ${amTimes.length} AM rush trips and ${pmTimes.length} PM rush trips.`); -}function applyRushHours() { - const amStart = document.getElementById("rush-am-start").value; - const amEnd = document.getElementById("rush-am-end").value; - const amInterval = parseInt(document.getElementById("rush-am-interval").value, 10); - - const pmStart = document.getElementById("rush-pm-start").value; - const pmEnd = document.getElementById("rush-pm-end").value; - const pmInterval = parseInt(document.getElementById("rush-pm-interval").value, 10); - - const timesInput = document.querySelector('.departure-times'); - let existingTimes = timesInput.value.split(',').map(t => t.trim()).filter(Boolean); - - // Helper function to generate times for a rush period - function generateRushTimes(start, end, interval) { - if (!start || !end || !interval || interval <= 0) return []; - - const times = []; - let [startHour, startMin] = start.split(":").map(Number); - const [endHour, endMin] = end.split(":").map(Number); - - while (startHour < endHour || (startHour === endHour && startMin <= endMin)) { - times.push(`${String(startHour).padStart(2, "0")}:${String(startMin).padStart(2, "0")}`); - startMin += interval; - if (startMin >= 60) { - startHour += Math.floor(startMin / 60); - startMin = startMin % 60; - } - } - - return times; - } - - // Generate AM rush times - const amTimes = generateRushTimes(amStart, amEnd, amInterval); - - // Generate PM rush times - const pmTimes = generateRushTimes(pmStart, pmEnd, pmInterval); - - // Merge all times and remove duplicates - const allTimes = [...existingTimes, ...amTimes, ...pmTimes]; - - // Sort times and remove duplicates - const uniqueTimes = [...new Set(allTimes)].sort((a, b) => { - const [aH, aM] = a.split(':').map(Number); - const [bH, bM] = b.split(':').map(Number); - return (aH * 60 + aM) - (bH * 60 + bM); - }); - - timesInput.value = uniqueTimes.join(", "); - generateStopTimesJSON(); - alert(`Added ${amTimes.length} AM rush trips and ${pmTimes.length} PM rush trips.`); }