diff --git a/MaintenanceWorker/src/web/mod.rs b/MaintenanceWorker/src/web/mod.rs index 1f1945be3..c87f5106a 100644 --- a/MaintenanceWorker/src/web/mod.rs +++ b/MaintenanceWorker/src/web/mod.rs @@ -1,11 +1,11 @@ use crate::shared::CloudflareVariables; -use time::{format_description::well_known::Iso8601, macros::format_description}; +use time::macros::format_description; use worker::*; static PAGE_HTML: &str = include_str!("page.html"); pub fn get_html( - req: Request, + _req: Request, _ctx: RouteContext<()>, vars: CloudflareVariables, ) -> Result { @@ -21,14 +21,20 @@ pub fn get_html( } fn format_html_with_date(vars: CloudflareVariables) -> std::result::Result { - let Ok(formatted_date) = vars.end_date.format(&Iso8601::DEFAULT) else { + let Ok(formatted_date) = vars.end_date.format(format_description!( + "[day]/[month]/[year] [hour]:[minute]:[second] +[offset_hour]:[offset_minute]" + )) else { return Err("Failed to format parsed end date"); }; let final_html = PAGE_HTML .replace("{{ title }}", &vars.title) .replace("{{ body }}", &vars.body) - .replace("{{ end_date }}", &formatted_date); + .replace("{{ end_date }}", &formatted_date) + .replace( + "{{ timestamp }}", + &vars.end_date.unix_timestamp().to_string(), + ); return Ok(final_html); } diff --git a/MaintenanceWorker/src/web/page.html b/MaintenanceWorker/src/web/page.html index 6cd896e2b..be66734bd 100644 --- a/MaintenanceWorker/src/web/page.html +++ b/MaintenanceWorker/src/web/page.html @@ -75,9 +75,12 @@ return; } - console.log(dateElement.textContent); + const timestamp = dateElement.getAttribute("data-timestamp"); + if (!timestamp) { + return; + } - const dateObj = new Date(dateElement.textContent); + const dateObj = new Date(timestamp * 1000); document.getElementById("date").textContent = dateObj.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "medium" @@ -94,8 +97,7 @@

{{ title }}


Expected end time:

-

{{ end_date }}

-

+

{{ end_date }}