1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 02:57:44 +00:00

Merge pull request #8164 from cakebaker/uptime_improve_uptime_since

uptime: improve readability of `uptime_since`
This commit is contained in:
Sylvestre Ledru 2025-06-21 19:45:56 +02:00 committed by GitHub
commit f825409392
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -188,20 +188,17 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
fn uptime_since() -> UResult<()> {
#[cfg(unix)]
#[cfg(not(target_os = "openbsd"))]
let uptime = {
let (boot_time, _) = process_utmpx(None);
#[cfg(target_os = "openbsd")]
let uptime = get_uptime(None)?;
#[cfg(unix)]
#[cfg(not(target_os = "openbsd"))]
let uptime = get_uptime(boot_time)?;
#[cfg(target_os = "windows")]
get_uptime(boot_time)?
};
#[cfg(any(windows, target_os = "openbsd"))]
let uptime = get_uptime(None)?;
let initial_date = Local
let since_date = Local
.timestamp_opt(Utc::now().timestamp() - uptime, 0)
.unwrap();
println!("{}", initial_date.format("%Y-%m-%d %H:%M:%S"));
println!("{}", since_date.format("%Y-%m-%d %H:%M:%S"));
Ok(())
}