My omnium-gatherom of scripts and source code.
at main 18 lines 706 B view raw
1use chrono::{Utc}; 2 3fn make_bar(start: i64, end: i64) -> String { 4 let bar_len = 46; 5 let now = Utc::now().timestamp(); 6 let percent = (now - start) as f64 / ((end - start) as f64); 7 let complete_n = (percent * bar_len as f64) as usize; 8 let complete = std::iter::repeat("#").take(complete_n).collect::<String>(); 9 let remaining = std::iter::repeat("-").take(bar_len - complete_n).collect::<String>(); 10 let seconds = (now - end) / 60; 11 let minutes = (now - end) % 60; 12 return format!("{s}:{m} [{c}{r}] {p}%", s = seconds, m = minutes, c = complete, r = remaining, p = (percent * 100.0) as i32); 13} 14 15fn main() { 16 println!("{}", make_bar(1695386666 -1800, 1695386666 + 3600)) 17 18}