Skip to content

Commit

Permalink
feat: Change duration formatting to be more human readable.
Browse files Browse the repository at this point in the history
Note that this changes duration output from something like `69d10h40m`
to `69d 10h 40m`.
  • Loading branch information
Byron committed Oct 24, 2023
2 parents bb1eadf + d032106 commit 6acf6fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 }
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions src/unit/duration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::fmt;
use std::{fmt, time};

use humantime::format_duration;

use crate::{progress::Step, unit::DisplayValue};

Expand All @@ -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<Step>) -> fmt::Result {
w.write_str(&compound_duration::format_dhms(value))
w.write_str(&format_duration(time::Duration::new(value as u64, 0)).to_string())
}
fn separator(&self, w: &mut dyn fmt::Write, _value: Step, _upper: Option<Step>) -> 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(time::Duration::new(upper_bound as u64, 0)).to_string())
}

fn dyn_hash(&self, state: &mut dyn std::hash::Hasher) {
Expand Down

0 comments on commit 6acf6fe

Please sign in to comment.