This is an automated email from the ASF dual-hosted git repository. tison pushed a commit to branch jiff in repository https://gitbox.apache.org/repos/asf/opendal-reqsign.git
commit 873ad858992d555879e47131d525a447d705e0b7 Author: tison <[email protected]> AuthorDate: Mon Sep 22 23:09:39 2025 +0800 refactor: chrono to jiff Signed-off-by: tison <[email protected]> --- Cargo.toml | 3 +- core/Cargo.toml | 2 +- core/src/time.rs | 68 ++++++------------------------------- services/aliyun-oss/Cargo.toml | 2 +- services/aws-v4/Cargo.toml | 2 +- services/azure-storage/Cargo.toml | 2 +- services/google/Cargo.toml | 2 +- services/huaweicloud-obs/Cargo.toml | 2 +- services/oracle/Cargo.toml | 4 +-- services/tencent-cos/Cargo.toml | 2 +- 10 files changed, 20 insertions(+), 69 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0feb155..90c7dbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,15 +32,14 @@ anyhow = "1" async-trait = "0.1" base64 = "0.22" bytes = "1" -chrono = "0.4.35" criterion = { version = "0.7.0", features = ["async_tokio", "html_reports"] } dotenv = "0.15" env_logger = "0.11" form_urlencoded = "1" hex = "0.4" hmac = "0.12" -home = "0.5" http = "1" +jiff = "0.2" log = "0.4" macro_rules_attribute = "0.2.0" once_cell = "1" diff --git a/core/Cargo.toml b/core/Cargo.toml index 124566c..e0f5037 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -32,11 +32,11 @@ anyhow.workspace = true async-trait.workspace = true base64.workspace = true bytes.workspace = true -chrono.workspace = true form_urlencoded.workspace = true hex.workspace = true hmac.workspace = true http.workspace = true +jiff.workspace = true log.workspace = true percent-encoding.workspace = true sha1.workspace = true diff --git a/core/src/time.rs b/core/src/time.rs index b8cb500..c987010 100644 --- a/core/src/time.rs +++ b/core/src/time.rs @@ -18,68 +18,26 @@ //! Time related utils. use crate::Error; -use chrono::format::Fixed; -use chrono::format::Item; -use chrono::format::Numeric; -use chrono::format::Pad; -use chrono::SecondsFormat; -use chrono::Utc; +use std::str::FromStr; /// DateTime is the alias for chrono::DateTime<Utc>. -pub type DateTime = chrono::DateTime<Utc>; +pub type DateTime = jiff::Timestamp; /// Create datetime of now. pub fn now() -> DateTime { - Utc::now() + jiff::Timestamp::now() } -/// DATE is a time format like `20220301` -const DATE: &[Item<'static>] = &[ - Item::Numeric(Numeric::Year, Pad::Zero), - Item::Numeric(Numeric::Month, Pad::Zero), - Item::Numeric(Numeric::Day, Pad::Zero), -]; - /// Format time into date: `20220301` pub fn format_date(t: DateTime) -> String { - t.format_with_items(DATE.iter()).to_string() + t.strftime("%Y%m%d").to_string() } -/// ISO8601 is a time format like `20220313T072004Z`. -const ISO8601: &[Item<'static>] = &[ - Item::Numeric(Numeric::Year, Pad::Zero), - Item::Numeric(Numeric::Month, Pad::Zero), - Item::Numeric(Numeric::Day, Pad::Zero), - Item::Literal("T"), - Item::Numeric(Numeric::Hour, Pad::Zero), - Item::Numeric(Numeric::Minute, Pad::Zero), - Item::Numeric(Numeric::Second, Pad::Zero), - Item::Literal("Z"), -]; - /// Format time into ISO8601: `20220313T072004Z` pub fn format_iso8601(t: DateTime) -> String { - t.format_with_items(ISO8601.iter()).to_string() + t.strftime("%Y%m%dT%H%M%SZ").to_string() } -/// HTTP_DATE is a time format like `Sun, 06 Nov 1994 08:49:37 GMT`. -const HTTP_DATE: &[Item<'static>] = &[ - Item::Fixed(Fixed::ShortWeekdayName), - Item::Literal(", "), - Item::Numeric(Numeric::Day, Pad::Zero), - Item::Literal(" "), - Item::Fixed(Fixed::ShortMonthName), - Item::Literal(" "), - Item::Numeric(Numeric::Year, Pad::Zero), - Item::Literal(" "), - Item::Numeric(Numeric::Hour, Pad::Zero), - Item::Literal(":"), - Item::Numeric(Numeric::Minute, Pad::Zero), - Item::Literal(":"), - Item::Numeric(Numeric::Second, Pad::Zero), - Item::Literal(" GMT"), -]; - /// Format time into http date: `Sun, 06 Nov 1994 08:49:37 GMT` /// /// ## Note @@ -89,12 +47,12 @@ const HTTP_DATE: &[Item<'static>] = &[ /// - Timezone is fixed to GMT. /// - Day must be 2 digit. pub fn format_http_date(t: DateTime) -> String { - t.format_with_items(HTTP_DATE.iter()).to_string() + t.strftime("%a, %d %b %Y %T GMT").to_string() } /// Format time into RFC3339: `2022-03-13T07:20:04Z` pub fn format_rfc3339(t: DateTime) -> String { - t.to_rfc3339_opts(SecondsFormat::Secs, true) + t.strftime("%FT%TZ").to_string() } /// Parse time from RFC3339. @@ -105,21 +63,17 @@ pub fn format_rfc3339(t: DateTime) -> String { /// - `2022-03-01T08:12:34+00:00` /// - `2022-03-01T08:12:34.00+00:00` pub fn parse_rfc3339(s: &str) -> crate::Result<DateTime> { - Ok(chrono::DateTime::parse_from_rfc3339(s) - .map_err(|err| { - Error::unexpected(format!("parse '{s}' into rfc3339 failed")).with_source(err) - })? - .with_timezone(&Utc)) + FromStr::from_str(s).map_err(|err| { + Error::unexpected(format!("parse '{s}' into rfc3339 failed")).with_source(err) + }) } #[cfg(test)] mod tests { - use chrono::TimeZone; - use super::*; fn test_time() -> DateTime { - Utc.with_ymd_and_hms(2022, 3, 1, 8, 12, 34).unwrap() + "2022-03-01T08:12:34Z".parse().unwrap() } #[test] diff --git a/services/aliyun-oss/Cargo.toml b/services/aliyun-oss/Cargo.toml index 5521684..62150ed 100644 --- a/services/aliyun-oss/Cargo.toml +++ b/services/aliyun-oss/Cargo.toml @@ -29,7 +29,7 @@ repository.workspace = true [dependencies] anyhow.workspace = true async-trait.workspace = true -chrono.workspace = true +jiff.workspace = true http.workspace = true log.workspace = true once_cell.workspace = true diff --git a/services/aws-v4/Cargo.toml b/services/aws-v4/Cargo.toml index 80df230..3746d01 100644 --- a/services/aws-v4/Cargo.toml +++ b/services/aws-v4/Cargo.toml @@ -34,7 +34,7 @@ name = "aws" anyhow.workspace = true async-trait.workspace = true bytes = "1.7.2" -chrono.workspace = true +jiff.workspace = true form_urlencoded.workspace = true http.workspace = true log.workspace = true diff --git a/services/azure-storage/Cargo.toml b/services/azure-storage/Cargo.toml index 788cb83..3701dce 100644 --- a/services/azure-storage/Cargo.toml +++ b/services/azure-storage/Cargo.toml @@ -31,7 +31,7 @@ anyhow.workspace = true async-trait.workspace = true base64.workspace = true bytes.workspace = true -chrono.workspace = true +jiff.workspace = true form_urlencoded.workspace = true http.workspace = true log.workspace = true diff --git a/services/google/Cargo.toml b/services/google/Cargo.toml index cfb86d2..eac5b43 100644 --- a/services/google/Cargo.toml +++ b/services/google/Cargo.toml @@ -28,7 +28,7 @@ repository.workspace = true [dependencies] async-trait.workspace = true -chrono.workspace = true +jiff.workspace = true http.workspace = true jsonwebtoken = "9.2" log.workspace = true diff --git a/services/huaweicloud-obs/Cargo.toml b/services/huaweicloud-obs/Cargo.toml index 6842eb2..4d24274 100644 --- a/services/huaweicloud-obs/Cargo.toml +++ b/services/huaweicloud-obs/Cargo.toml @@ -29,7 +29,7 @@ repository.workspace = true [dependencies] anyhow.workspace = true async-trait.workspace = true -chrono.workspace = true +jiff.workspace = true http.workspace = true log.workspace = true once_cell.workspace = true diff --git a/services/oracle/Cargo.toml b/services/oracle/Cargo.toml index 651bb28..67eb438 100644 --- a/services/oracle/Cargo.toml +++ b/services/oracle/Cargo.toml @@ -30,14 +30,12 @@ repository.workspace = true anyhow.workspace = true async-trait.workspace = true base64.workspace = true -chrono.workspace = true +jiff.workspace = true http.workspace = true log.workspace = true reqsign-core.workspace = true rsa.workspace = true rust-ini.workspace = true -serde.workspace = true - [dev-dependencies] env_logger = "0.11" diff --git a/services/tencent-cos/Cargo.toml b/services/tencent-cos/Cargo.toml index 298fd38..4d23568 100644 --- a/services/tencent-cos/Cargo.toml +++ b/services/tencent-cos/Cargo.toml @@ -30,7 +30,7 @@ repository.workspace = true [dependencies] anyhow.workspace = true async-trait.workspace = true -chrono.workspace = true +jiff.workspace = true http.workspace = true log.workspace = true percent-encoding.workspace = true
