add live updating table
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 9m20s

This commit is contained in:
Nicholas Orlowsky 2026-01-14 23:18:35 -05:00
parent 2ca76548d6
commit 6773e6ae30
No known key found for this signature in database
GPG key ID: A9F3BA4C0AA7A70B
7 changed files with 210 additions and 124 deletions

View file

@ -77,6 +77,13 @@ pub struct StopTemplate {
pub current_time: i64
}
#[derive(askama::Template)]
#[template(path = "stop_table_impl.html")]
pub struct StopTableTemplate {
pub trips: Vec<TripPerspective>,
pub current_time: i64
}
pub fn build_timetables(
directions: Vec<Direction>,
trips: Vec<Trip>,
@ -183,6 +190,7 @@ mod filters {
return Ok(format!("{}ns", nanos));
}
}
pub fn format_time(
seconds_since_midnight: &i64,
_: &dyn askama::Values,
@ -190,8 +198,10 @@ mod filters {
let total_minutes = seconds_since_midnight / 60;
let (hours, ampm) = {
let hrs = total_minutes / 60;
if hrs >= 12 {
if hrs > 12 {
(hrs - 12, "PM")
} else if hrs == 12 {
(12, "PM")
} else if hrs > 0 {
(hrs, "AM")
} else {
@ -201,4 +211,26 @@ mod filters {
let minutes = total_minutes % 60;
Ok(format!("{}:{:02} {}", hours, minutes, ampm))
}
pub fn format_time_with_seconds(
seconds_since_midnight: &i64,
_: &dyn askama::Values,
) -> askama::Result<String> {
let total_minutes = seconds_since_midnight / 60;
let (hours, ampm) = {
let hrs = total_minutes / 60;
if hrs > 12 {
(hrs - 12, "PM")
} else if hrs == 12 {
(12, "PM")
} else if hrs > 0 {
(hrs, "AM")
} else {
(12, "AM")
}
};
let minutes = total_minutes % 60;
let seconds = seconds_since_midnight % 60;
Ok(format!("{}:{:02}:{:02} {}", hours, minutes, seconds, ampm))
}
}