From f5143c98be0f2f2267c4574805f81a61cd8d613a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Kj=C3=A4ll?= Date: Tue, 24 Oct 2023 17:26:07 +0200 Subject: [PATCH] replace compound_duration with humantime This is the humantime part of PR https://github.com/Byron/prodash/pull/25 --- Cargo.toml | 5 ++--- README.md | 2 +- src/unit/duration.rs | 8 +++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 39b29b2..741390e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ progress-tree-log = ["log"] progress-log = ["log"] unit-bytes = ["bytesize"] unit-human = ["human_format"] -unit-duration = ["compound_duration"] +unit-duration = ["humantime"] render-tui-termion = ["crosstermion/tui-react-termion"] render-tui-crossterm = ["crosstermion/tui-react-crossterm", "crosstermion/input-async-crossterm"] render-tui = ["tui", @@ -76,7 +76,7 @@ tui = { package = "ratatui", version = "0.20.1", optional = true, default-featur tui-react = { version = "0.20.0", optional = true } futures-core = { version = "0.3.4", optional = true, default-features = false } futures-lite = { version = "1.5.0", optional = true } -humantime = { version = "2.0.0", optional = true } +humantime = { version = "2.1.0", optional = true } unicode-segmentation = { version = "1.6.0", optional = true } unicode-width = { version = "0.1.7", optional = true } crosstermion = { version = "0.11.0", optional = true, default-features = false } @@ -93,7 +93,6 @@ is-terminal = { version = "0.4.9", optional = true } # units bytesize = { version = "1.0.1", optional = true } human_format = { version = "1.0.3", optional = true } -compound_duration = { version = "1.2.0", optional = true } [package.metadata.docs.rs] all-features = true diff --git a/README.md b/README.md index c9fbbb5..f470fdc 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ This crate comes with various cargo features to tailor it to your needs. * **unit-human** * Display counts in a way that is easier to grasp for humans, using the tiny `human_format` crate. * **unit-duration** - * Displays time in seconds like '_5m4s_' using the tiny `compound_duration` crate. + * Displays time in seconds like '_5m4s_' using the tiny `humantime` crate. ## Features diff --git a/src/unit/duration.rs b/src/unit/duration.rs index 0da23e8..0a464ce 100644 --- a/src/unit/duration.rs +++ b/src/unit/duration.rs @@ -1,4 +1,6 @@ -use std::fmt; +use std::{fmt, time::Duration as StdDuration}; + +use humantime::format_duration; use crate::{progress::Step, unit::DisplayValue}; @@ -8,13 +10,13 @@ pub struct Duration; impl DisplayValue for Duration { fn display_current_value(&self, w: &mut dyn fmt::Write, value: Step, _upper: Option) -> fmt::Result { - w.write_str(&compound_duration::format_dhms(value)) + w.write_str(&format_duration(StdDuration::new(value as u64, 0)).to_string()) } fn separator(&self, w: &mut dyn fmt::Write, _value: Step, _upper: Option) -> fmt::Result { w.write_str(" of ") } fn display_upper_bound(&self, w: &mut dyn fmt::Write, upper_bound: Step, _value: Step) -> fmt::Result { - w.write_str(&compound_duration::format_dhms(upper_bound)) + w.write_str(&format_duration(StdDuration::new(upper_bound as u64, 0)).to_string()) } fn dyn_hash(&self, state: &mut dyn std::hash::Hasher) {