aboutsummaryrefslogtreecommitdiff
path: root/src/history.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/history.rs')
-rw-r--r--src/history.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/history.rs b/src/history.rs
index 5216d10..f8ffec2 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -13,6 +13,11 @@ pub struct History {
data: Vec<Reading>,
}
+pub enum NoETA {
+ Pending,
+ Fuck,
+}
+
impl History {
pub fn record(&mut self, queue_size: u32) {
self.data.push(Reading {
@@ -21,30 +26,31 @@ impl History {
});
}
- pub fn completion_time(&self) -> Option<js_sys::Date> {
+ pub fn completion_time(&self) -> Result<js_sys::Date, NoETA> {
// TODO make this not suck
let &Reading {
time: first_time,
queue_size: first_size,
..
- } = self.data.first()?;
+ } = self.data.first().ok_or(NoETA::Pending)?;
let &Reading {
time: last_time,
queue_size: last_size,
- } = self.data.last()?;
+ } = self.data.last().ok_or(NoETA::Pending)?;
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;
+ return Err(NoETA::Pending);
}
+ let overall_queue_motion = match first_size.checked_sub(last_size) {
+ Some(0) => return Err(NoETA::Pending),
+ Some(x) => x,
+ None => return Err(NoETA::Fuck),
+ };
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(
+ Ok(js_sys::Date::new(&JsValue::from(
completion_time_gmt as f64,
)))
}