mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Merge pull request #8164 from cakebaker/uptime_improve_uptime_since
uptime: improve readability of `uptime_since`
This commit is contained in:
commit
f825409392
1 changed files with 7 additions and 10 deletions
|
@ -188,20 +188,17 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
|
||||||
fn uptime_since() -> UResult<()> {
|
fn uptime_since() -> UResult<()> {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[cfg(not(target_os = "openbsd"))]
|
#[cfg(not(target_os = "openbsd"))]
|
||||||
let (boot_time, _) = process_utmpx(None);
|
let uptime = {
|
||||||
|
let (boot_time, _) = process_utmpx(None);
|
||||||
#[cfg(target_os = "openbsd")]
|
get_uptime(boot_time)?
|
||||||
let uptime = get_uptime(None)?;
|
};
|
||||||
#[cfg(unix)]
|
#[cfg(any(windows, target_os = "openbsd"))]
|
||||||
#[cfg(not(target_os = "openbsd"))]
|
|
||||||
let uptime = get_uptime(boot_time)?;
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
let uptime = get_uptime(None)?;
|
let uptime = get_uptime(None)?;
|
||||||
|
|
||||||
let initial_date = Local
|
let since_date = Local
|
||||||
.timestamp_opt(Utc::now().timestamp() - uptime, 0)
|
.timestamp_opt(Utc::now().timestamp() - uptime, 0)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("{}", initial_date.format("%Y-%m-%d %H:%M:%S"));
|
println!("{}", since_date.format("%Y-%m-%d %H:%M:%S"));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue