zvault/src/util/cli.rs

39 lines
947 B
Rust
Raw Normal View History

2017-03-16 19:05:58 +00:00
pub fn to_file_size(size: u64) -> String {
let mut size = size as f32;
if size >= 512.0 {
size /= 1024.0;
} else {
return format!("{:.0} Bytes", size);
}
if size >= 512.0 {
size /= 1024.0;
} else {
return format!("{:.1} KiB", size);
}
if size >= 512.0 {
size /= 1024.0;
} else {
return format!("{:.1} MiB", size);
}
if size >= 512.0 {
size /= 1024.0;
} else {
return format!("{:.1} GiB", size);
}
format!("{:.1} TiB", size)
}
2017-03-17 10:03:07 +00:00
pub fn to_speed(size: u64, dur: f32) -> String {
let speed = (size as f32 / dur) as u64;
to_file_size(speed) + "/s"
}
2017-03-16 19:05:58 +00:00
pub fn to_duration(dur: f32) -> String {
let secs = dur.floor() as u64;
let subsecs = dur - dur.floor();
let hours = secs / 3600;
let mins = (secs / 60) % 60;
let secs = (secs % 60) as f32 + subsecs;
format!("{}:{:02}:{:04.1}", hours, mins, secs)
}