Skip to content

Commit f4f7963

Browse files
committed
w: misc test and code quality fixes
1 parent 0947531 commit f4f7963

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/uu/w/src/w.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct UserInfo {
2323
user: String,
2424
terminal: String,
2525
login_time: String,
26-
idle_time: Duration, // for better compatiability with old-style outputs
26+
idle_time: Duration, // for better compatibility with old-style outputs
2727
jcpu: String,
2828
pcpu: String,
2929
command: String,
@@ -99,11 +99,8 @@ fn _fetch_idle_time(_tty: String) -> Result<Duration, std::io::Error> {
9999
Ok(Duration::ZERO)
100100
}
101101

102-
fn format_time_elapsed(
103-
time: Duration,
104-
old_style: bool,
105-
) -> Result<String, chrono::format::ParseError> {
106-
let t = chrono::Duration::from_std(time).unwrap();
102+
fn format_time_elapsed(time: Duration, old_style: bool) -> Result<String, chrono::OutOfRangeError> {
103+
let t = chrono::Duration::from_std(time)?;
107104
if t.num_days() >= 2 {
108105
Ok(format!("{}days", t.num_days()))
109106
} else if t.num_hours() >= 1 {
@@ -343,6 +340,10 @@ mod tests {
343340
format_time_elapsed(td, false).unwrap(),
344341
String::from("18:18m")
345342
);
343+
assert_eq!(
344+
format_time_elapsed(td, true).unwrap(),
345+
String::from("18:18")
346+
);
346347
}
347348

348349
#[test]

0 commit comments

Comments
 (0)