Skip to content

Commit f825409

Browse files
authored
Merge pull request #8164 from cakebaker/uptime_improve_uptime_since
uptime: improve readability of `uptime_since`
2 parents 7b3247d + 54d61cb commit f825409

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/uu/uptime/src/uptime.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,17 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
188188
fn uptime_since() -> UResult<()> {
189189
#[cfg(unix)]
190190
#[cfg(not(target_os = "openbsd"))]
191-
let (boot_time, _) = process_utmpx(None);
192-
193-
#[cfg(target_os = "openbsd")]
194-
let uptime = get_uptime(None)?;
195-
#[cfg(unix)]
196-
#[cfg(not(target_os = "openbsd"))]
197-
let uptime = get_uptime(boot_time)?;
198-
#[cfg(target_os = "windows")]
191+
let uptime = {
192+
let (boot_time, _) = process_utmpx(None);
193+
get_uptime(boot_time)?
194+
};
195+
#[cfg(any(windows, target_os = "openbsd"))]
199196
let uptime = get_uptime(None)?;
200197

201-
let initial_date = Local
198+
let since_date = Local
202199
.timestamp_opt(Utc::now().timestamp() - uptime, 0)
203200
.unwrap();
204-
println!("{}", initial_date.format("%Y-%m-%d %H:%M:%S"));
201+
println!("{}", since_date.format("%Y-%m-%d %H:%M:%S"));
205202

206203
Ok(())
207204
}

0 commit comments

Comments
 (0)