Skip to content

Replace humantime crate with jiff #7261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions object_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ readme = "README.md"
description = "A generic object store interface for uniformly interacting with AWS S3, Google Cloud Storage, Azure Blob Storage and local files."
keywords = ["object", "storage", "cloud"]
repository = "https://github.com/apache/arrow-rs/tree/main/object_store"
rust-version = "1.64.0"
rust-version = "1.70.0"

[package.metadata.docs.rs]
all-features = true
Expand All @@ -35,8 +35,8 @@ bytes = "1.0"
chrono = { version = "0.4.34", default-features = false, features = ["clock"] }
futures = "0.3"
http = "1.2.0"
humantime = "2.1"
itertools = "0.14.0"
jiff = { version = "0.2", default-features = false }
parking_lot = { version = "0.12" }
percent-encoding = "2.1"
thiserror = "2.0.2"
Expand Down
28 changes: 22 additions & 6 deletions object_store/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::fmt::{Debug, Display, Formatter};
use std::str::FromStr;
use std::time::Duration;

use humantime::{format_duration, parse_duration};
use jiff::SignedDuration;
use reqwest::header::HeaderValue;

use crate::{Error, Result};
Expand Down Expand Up @@ -87,10 +87,12 @@ impl Parse for bool {

impl Parse for Duration {
fn parse(v: &str) -> Result<Self> {
parse_duration(v).map_err(|_| Error::Generic {
store: "Config",
source: format!("failed to parse \"{v}\" as Duration").into(),
})
SignedDuration::from_str(v)
.and_then(Self::try_from)
.map_err(|_| Error::Generic {
store: "Config",
source: format!("failed to parse \"{v}\" as Duration").into(),
})
}
}

Expand Down Expand Up @@ -123,7 +125,12 @@ impl Parse for HeaderValue {

pub(crate) fn fmt_duration(duration: &ConfigValue<Duration>) -> String {
match duration {
ConfigValue::Parsed(v) => format_duration(*v).to_string(),
ConfigValue::Parsed(v) => {
// Should only fail if `Duration` has more seconds than what fits
// into i64.
let d = SignedDuration::try_from(*v).unwrap();
format!("{:#}", d)
}
ConfigValue::Deferred(v) => v.clone(),
}
}
Expand All @@ -140,4 +147,13 @@ mod tests {
assert_eq!(Duration::parse("60 s").unwrap(), duration);
assert_eq!(Duration::parse("60s").unwrap(), duration)
}

#[test]
fn test_fmt_duration() {
let dur = ConfigValue::Parsed(Duration::new(9420, 0));
assert_eq!("2h 37m", fmt_duration(&dur));

let dur = ConfigValue::Parsed(Duration::new(0, 32_000_000));
assert_eq!("32ms", fmt_duration(&dur));
}
}
Loading