Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T01:51:01.975Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

time.rs

34 lines · 1.1 KB · rust
1use std::time::Duration;
2
3pub fn duration_alt_display(duration: Duration) -> String {
4    let hours = duration.as_secs() / 3600;
5    let minutes = (duration.as_secs() % 3600) / 60;
6    let seconds = duration.as_secs() % 60;
7
8    if hours > 0 {
9        format!("{hours}h {minutes}m {seconds}s")
10    } else if minutes > 0 {
11        format!("{minutes}m {seconds}s")
12    } else {
13        format!("{seconds}s")
14    }
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20
21    #[test]
22    fn test_duration_alt_display() {
23        use duration_alt_display as f;
24        assert_eq!("0s", f(Duration::from_secs(0)));
25        assert_eq!("59s", f(Duration::from_secs(59)));
26        assert_eq!("1m 0s", f(Duration::from_secs(60)));
27        assert_eq!("10m 0s", f(Duration::from_secs(600)));
28        assert_eq!("1h 0m 0s", f(Duration::from_secs(3600)));
29        assert_eq!("3h 2m 1s", f(Duration::from_secs(3600 * 3 + 60 * 2 + 1)));
30        assert_eq!("23h 59m 59s", f(Duration::from_secs(3600 * 24 - 1)));
31        assert_eq!("100h 0m 0s", f(Duration::from_secs(3600 * 100)));
32    }
33}
34
Served at tenant.openagents/omega Member data and write actions are omitted.