// god is dead and we have killed him and consequently std::time::Instant doesn't work on wasm use chrono::prelude::*; use wasm_bindgen::prelude::*; struct Reading { time: DateTime, queue_size: u32, } #[derive(Default)] pub struct History { data: Vec, } impl History { pub fn record(&mut self, queue_size: u32) { self.data.push(Reading { time: Local::now(), queue_size, }); } pub fn completion_time(&self) -> Option { // TODO make this not suck let &Reading { time: first_time, queue_size: first_size, .. } = self.data.first()?; let &Reading { time: last_time, queue_size: last_size, } = self.data.last()?; let overall_time_elapsed = last_time - first_time; if overall_time_elapsed.is_zero() { return None; } let overall_queue_motion = first_size - last_size; if overall_queue_motion == 0 { return None; } gloo::console::log!( "time", overall_time_elapsed.to_string(), "motion", overall_queue_motion ); let duration_per_step = overall_time_elapsed / overall_queue_motion as i32; let remaining_duration = duration_per_step * last_size as i32; let completion_time = last_time + remaining_duration; let completion_time_gmt = completion_time.timestamp_millis(); Some(js_sys::Date::new(&JsValue::from( completion_time_gmt as f64, ))) } }