-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Should never have added it. Annoyingly long compile times for no reason...
- Loading branch information
Showing
6 changed files
with
21 additions
and
128 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,20 @@ | ||
use color_eyre::Result; | ||
use nix::sys::sysinfo::sysinfo; | ||
use std::io; | ||
|
||
pub fn get_current() -> Result<String, io::Error> { | ||
let info = sysinfo().map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; | ||
let uptime_seconds = info.uptime().as_secs_f64(); | ||
let uptime_seconds = info.uptime().as_secs(); | ||
|
||
let total_minutes = (uptime_seconds / 60.0).round() as u64; | ||
let total_minutes = uptime_seconds / 60; | ||
let days = total_minutes / (60 * 24); | ||
let hours = (total_minutes % (60 * 24)) / 60; | ||
let minutes = total_minutes % 60; | ||
|
||
let mut parts = Vec::with_capacity(3); | ||
if days > 0 { | ||
parts.push(format!("{days} days")); | ||
} | ||
if hours > 0 || days > 0 { | ||
parts.push(format!("{hours} hours")); | ||
} | ||
if minutes > 0 || hours > 0 || days > 0 { | ||
parts.push(format!("{minutes} minutes")); | ||
} | ||
let parts = [(days, "day"), (hours, "hour"), (minutes, "minute")] | ||
.iter() | ||
.filter(|&&(value, _)| value > 0) | ||
.map(|&(value, label)| format!("{value} {label}{}", if value > 1 { "s" } else { "" })) | ||
.collect::<Vec<_>>(); | ||
|
||
Ok(parts.join(", ")) | ||
} |