blob: 7c0e23f727db0f6c84b8534c8e432ef1676096d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
use std::time;
use super::unix;
pub fn file_size_to_string(mut file_size: u64) -> String {
const FILE_UNITS: [&str; 6] = ["B", "K", "M", "G", "T", "E"];
const CONV_RATE: f64 = 1024.0;
let mut file_size: f64 = file_size as f64;
let mut index = 0;
while file_size > CONV_RATE {
file_size /= CONV_RATE;
index += 1;
}
if file_size >= 100.0 {
format!("{:>4.0} {}", file_size, FILE_UNITS[index])
} else if file_size >= 10.0 {
format!("{:>4.1} {}", file_size, FILE_UNITS[index])
} else {
format!("{:>4.2} {}", file_size, FILE_UNITS[index])
}
}
pub fn mode_to_string(mode: u32) -> String {
unix::stringify_mode(mode)
}
pub fn mtime_to_string(mtime: time::SystemTime) -> String {
const MTIME_FORMATTING: &str = "%Y-%m-%d %H:%M";
let datetime: chrono::DateTime<chrono::offset::Utc> = mtime.into();
datetime.format(MTIME_FORMATTING).to_string()
}
|