Skip to content

Commit 389e9ed

Browse files
committed
render: switch from humantime to jiff
Since prodash switched over to Jiff, Jiff has grown support for the "friendly" duration format. It is meant to be a replacement for `humantime` formatting of durations.
1 parent 373b6b1 commit 389e9ed

File tree

6 files changed

+19
-31
lines changed

6 files changed

+19
-31
lines changed

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ progress-tree-log = ["log"]
3939
progress-log = ["log"]
4040
unit-bytes = ["bytesize"]
4141
unit-human = ["human_format"]
42-
unit-duration = ["humantime"]
42+
unit-duration = ["jiff"]
4343
render-tui-crossterm = ["crosstermion/tui-react-crossterm", "crosstermion/input-async-crossterm"]
4444
render-tui = ["tui",
4545
"unicode-segmentation",
@@ -49,8 +49,8 @@ render-tui = ["tui",
4949
"futures-lite",
5050
"futures-core",
5151
"async-io",
52-
"humantime"]
53-
render-line = ["crosstermion/color", "humantime", "unicode-width"]
52+
"jiff"]
53+
render-line = ["crosstermion/color", "jiff", "unicode-width"]
5454
render-line-crossterm = ["crosstermion/crossterm"]
5555
render-line-autoconfigure = ["is-terminal"]
5656

@@ -69,7 +69,6 @@ tui = { package = "ratatui", version = "0.26.0", optional = true, default-featur
6969
tui-react = { version = "0.23.0", optional = true }
7070
futures-core = { version = "0.3.4", optional = true, default-features = false }
7171
futures-lite = { version = "2.1.0", optional = true }
72-
humantime = { version = "2.1.0", optional = true }
7372
unicode-segmentation = { version = "1.6.0", optional = true }
7473
unicode-width = { version = "0.1.7", optional = true }
7574
crosstermion = { version = "0.14.0", optional = true, default-features = false }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ This crate comes with various cargo features to tailor it to your needs.
7171
* **unit-human**
7272
* Display counts in a way that is easier to grasp for humans, using the tiny `human_format` crate.
7373
* **unit-duration**
74-
* Displays time in seconds like '_5m4s_' using the tiny `humantime` crate.
74+
* Displays time in seconds like '_5m4s_' using the `jiff` crate's friendly duration format.
7575

7676
## Features
7777

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub use log::info;
4646
#[cfg(feature = "progress-tree-log")]
4747
pub use log::warn;
4848

49-
#[cfg(any(feature = "humantime", feature = "local-time"))]
49+
#[cfg(any(feature = "jiff", feature = "local-time"))]
5050
///
5151
pub mod time;
5252

src/render/tui/draw/progress.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
use std::{
2-
fmt,
3-
sync::atomic::Ordering,
4-
time::{Duration, SystemTime},
5-
};
1+
use std::{fmt, sync::atomic::Ordering, time::Duration};
62

7-
use humantime::format_duration;
83
use tui::{
94
buffer::Buffer,
105
layout::Rect,
@@ -300,13 +295,14 @@ fn add_block_eta(state: progress::State, progress_text: &mut String) {
300295
progress_text.push_str(reason);
301296
progress_text.push(']');
302297
if let Some(eta) = maybe_eta {
303-
let now = SystemTime::now();
298+
let eta = jiff::Timestamp::try_from(eta).expect("reasonable system time");
299+
let now = jiff::Timestamp::now();
304300
if eta > now {
305301
use std::fmt::Write;
306302
write!(
307303
progress_text,
308-
" → {} to {}",
309-
format_duration(eta.duration_since(now).expect("computation to work")),
304+
" → {:#} to {}",
305+
eta.duration_since(now),
310306
if let progress::State::Blocked(_, _) = state {
311307
"unblock"
312308
} else {

src/time.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,16 @@ mod utc {
3636
///
3737
/// Available without the `localtime` feature toggle.
3838
pub fn format_time_for_messages(time: SystemTime) -> String {
39-
String::from_utf8_lossy(
40-
&humantime::format_rfc3339_seconds(time).to_string().as_bytes()
41-
[DATE_TIME_YMD..DATE_TIME_YMD + DATE_TIME_HMS],
42-
)
43-
.into_owned()
39+
let time = jiff::Timestamp::try_from(time).expect("reasonable system time");
40+
time.strftime("%T").to_string()
4441
}
4542

4643
/// Return a string representing the current time as UTC.
4744
///
4845
/// Available without the `localtime` feature toggle.
4946
pub fn format_now_datetime_seconds() -> String {
50-
String::from_utf8_lossy(
51-
&humantime::format_rfc3339_seconds(std::time::SystemTime::now())
52-
.to_string()
53-
.as_bytes()[.."2020-02-13T00:51:45".len()],
54-
)
55-
.into_owned()
47+
let time = jiff::Timestamp::try_from(time).expect("reasonable system time");
48+
time.strftime("%FT%T").to_string()
5649
}
5750
}
5851

src/unit/duration.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use std::{fmt, time};
2-
3-
use humantime::format_duration;
1+
use std::fmt;
42

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

@@ -10,13 +8,15 @@ pub struct Duration;
108

119
impl DisplayValue for Duration {
1210
fn display_current_value(&self, w: &mut dyn fmt::Write, value: Step, _upper: Option<Step>) -> fmt::Result {
13-
w.write_str(&format_duration(time::Duration::new(value as u64, 0)).to_string())
11+
let dur = jiff::SignedDuration::from_secs(value as i64);
12+
w.write_str(&format!("{dur:#}"))
1413
}
1514
fn separator(&self, w: &mut dyn fmt::Write, _value: Step, _upper: Option<Step>) -> fmt::Result {
1615
w.write_str(" of ")
1716
}
1817
fn display_upper_bound(&self, w: &mut dyn fmt::Write, upper_bound: Step, _value: Step) -> fmt::Result {
19-
w.write_str(&format_duration(time::Duration::new(upper_bound as u64, 0)).to_string())
18+
let dur = jiff::SignedDuration::from_secs(upper_bound as i64);
19+
w.write_str(&format!("{dur:#}"))
2020
}
2121

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

0 commit comments

Comments
 (0)