From 29d3145681529987f12fb90eb9da452b60810876 Mon Sep 17 00:00:00 2001 From: Sachymetsu Date: Wed, 28 Jan 2026 11:44:03 +0100 Subject: [PATCH] Switch to jiff for sachy-sntp --- Cargo.lock | 42 ++++++++++++++++++++++++++++++++---------- sachy-sntp/Cargo.toml | 6 +++--- sachy-sntp/src/lib.rs | 31 ++++++------------------------- 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c226e5c..c3619a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -120,15 +120,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" -[[package]] -name = "chrono" -version = "0.4.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" -dependencies = [ - "num-traits", -] - [[package]] name = "core-foundation" version = "0.10.1" @@ -664,6 +655,28 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +[[package]] +name = "jiff" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67e8da4c49d6d9909fe03361f9b620f58898859f5c7aded68351e85e71ecf50" +dependencies = [ + "jiff-static", + "portable-atomic", + "portable-atomic-util", +] + +[[package]] +name = "jiff-static" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0c84ee7f197eca9a86c6fd6cb771e55eb991632f15f2bc3ca6ec838929e6e78" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "libc" version = "0.2.179" @@ -975,6 +988,15 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" +[[package]] +name = "portable-atomic-util" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" +dependencies = [ + "portable-atomic", +] + [[package]] name = "prettyplease" version = "0.2.37" @@ -1258,10 +1280,10 @@ dependencies = [ name = "sachy-sntp" version = "0.1.0" dependencies = [ - "chrono", "defmt 1.0.1", "embassy-net", "embassy-time", + "jiff", "sachy-fmt", ] diff --git a/sachy-sntp/Cargo.toml b/sachy-sntp/Cargo.toml index c391260..0c3573e 100644 --- a/sachy-sntp/Cargo.toml +++ b/sachy-sntp/Cargo.toml @@ -8,7 +8,7 @@ version.workspace = true rust-version.workspace = true [dependencies] -chrono = { version = "0.4.41", default-features = false, optional = true } +jiff = { version = "0.2.18", default-features = false, optional = true } defmt = { workspace = true, optional = true } embassy-net = { workspace = true, features = [ "udp", @@ -20,7 +20,7 @@ embassy-time = { workspace = true, optional = true } sachy-fmt = { path = "../sachy-fmt" } [features] -default = ["chrono", "embassy-net"] -chrono = ["dep:chrono"] +default = ["jiff", "embassy-net"] +jiff = ["dep:jiff"] embassy-net = ["dep:embassy-net", "dep:embassy-time"] defmt = ["dep:defmt"] diff --git a/sachy-sntp/src/lib.rs b/sachy-sntp/src/lib.rs index 488dc84..1a975b7 100644 --- a/sachy-sntp/src/lib.rs +++ b/sachy-sntp/src/lib.rs @@ -67,13 +67,8 @@ impl SntpTimestamp { ntp_epoch_micros + offset } - #[cfg(feature = "chrono")] - pub fn try_to_utc(self) -> Result, SntpError> { - self.try_into() - } - - #[cfg(feature = "chrono")] - pub fn try_to_naive_datetime(self) -> Result { + #[cfg(feature = "jiff")] + pub fn try_to_unix_timestamp(self) -> Result { self.try_into() } } @@ -125,29 +120,15 @@ impl SntpRequest { Err(SntpError::InvalidPacket) } - - #[cfg(feature = "chrono")] - pub fn as_naive_datetime(raw_time: SntpTimestamp) -> Result { - raw_time.try_into() - } -} - -#[cfg(feature = "chrono")] -impl TryFrom for chrono::NaiveDateTime { - type Error = SntpError; - - fn try_from(timestamp: SntpTimestamp) -> Result { - Ok(chrono::DateTime::::try_from(timestamp)?.naive_utc()) - } } -#[cfg(feature = "chrono")] -impl TryFrom for chrono::DateTime { +#[cfg(feature = "jiff")] +impl TryFrom for jiff::Timestamp { type Error = SntpError; fn try_from(timestamp: SntpTimestamp) -> Result { - chrono::DateTime::::from_timestamp_micros(timestamp.utc_micros()) - .ok_or(SntpError::InvalidTime) + jiff::Timestamp::from_microsecond(timestamp.utc_micros()) + .map_err(|_| SntpError::InvalidTime) } } -- 2.51.2