Skip to content

Commit 73b300e

Browse files
committed
Replace humantime crate with jiff
1 parent f5138fc commit 73b300e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

object_store/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ bytes = "1.0"
3535
chrono = { version = "0.4.34", default-features = false, features = ["clock"] }
3636
futures = "0.3"
3737
http = "1.2.0"
38-
humantime = "2.1"
3938
itertools = "0.14.0"
39+
jiff = { version = "0.2", default-features = false }
4040
parking_lot = { version = "0.12" }
4141
percent-encoding = "2.1"
4242
thiserror = "2.0.2"

object_store/src/config.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::fmt::{Debug, Display, Formatter};
1818
use std::str::FromStr;
1919
use std::time::Duration;
2020

21-
use humantime::{format_duration, parse_duration};
21+
use jiff::SignedDuration;
2222
use reqwest::header::HeaderValue;
2323

2424
use crate::{Error, Result};
@@ -87,10 +87,12 @@ impl Parse for bool {
8787

8888
impl Parse for Duration {
8989
fn parse(v: &str) -> Result<Self> {
90-
parse_duration(v).map_err(|_| Error::Generic {
91-
store: "Config",
92-
source: format!("failed to parse \"{v}\" as Duration").into(),
93-
})
90+
SignedDuration::from_str(v)
91+
.and_then(Self::try_from)
92+
.map_err(|_| Error::Generic {
93+
store: "Config",
94+
source: format!("failed to parse \"{v}\" as Duration").into(),
95+
})
9496
}
9597
}
9698

@@ -123,7 +125,12 @@ impl Parse for HeaderValue {
123125

124126
pub(crate) fn fmt_duration(duration: &ConfigValue<Duration>) -> String {
125127
match duration {
126-
ConfigValue::Parsed(v) => format_duration(*v).to_string(),
128+
ConfigValue::Parsed(v) => {
129+
// Should only fail if `Duration` has more seconds than what fits
130+
// into i64.
131+
let d = SignedDuration::try_from(*v).unwrap();
132+
format!("{:#}", d)
133+
}
127134
ConfigValue::Deferred(v) => v.clone(),
128135
}
129136
}
@@ -140,4 +147,13 @@ mod tests {
140147
assert_eq!(Duration::parse("60 s").unwrap(), duration);
141148
assert_eq!(Duration::parse("60s").unwrap(), duration)
142149
}
150+
151+
#[test]
152+
fn test_fmt_duration() {
153+
let dur = ConfigValue::Parsed(Duration::new(9420, 0));
154+
assert_eq!("2h 37m", fmt_duration(&dur));
155+
156+
let dur = ConfigValue::Parsed(Duration::new(0, 32_000_000));
157+
assert_eq!("32ms", fmt_duration(&dur));
158+
}
143159
}

0 commit comments

Comments
 (0)