diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1547e62..0637896 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: matrix: rust: - stable - - 1.67 + - 1.70 include: - rust: stable extra_components: rustfmt diff --git a/CHANGELOG.md b/CHANGELOG.md index e87d037..73d4f9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## unreleased + +* update minimum Rust to 1.70. +* use [`jiff`](https://crates.io/crates/jiff) for date formatting. + ## `v0.4.9` (2024-08-19) * added helpers for building `.mp4` `VisualSampleEntry` and `AudioSampleEntry` diff --git a/Cargo.lock b/Cargo.lock index 6c574a3..8541012 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1083,6 +1083,31 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +[[package]] +name = "jiff" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2b7379a75544c94b3da32821b0bf41f9062e9970e23b78cc577d0d89676d16" +dependencies = [ + "jiff-tzdb-platform", + "windows-sys 0.52.0", +] + +[[package]] +name = "jiff-tzdb" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05fac328b3df1c0f18a3c2ab6cb7e06e4e549f366017d796e3e66b6d6889abe6" + +[[package]] +name = "jiff-tzdb-platform" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8da387d5feaf355954c2c122c194d6df9c57d865125a67984bb453db5336940" +dependencies = [ + "jiff-tzdb", +] + [[package]] name = "js-sys" version = "0.3.58" @@ -1720,6 +1745,7 @@ dependencies = [ "h264-reader", "hex", "http-auth", + "jiff", "log", "mylog", "once_cell", @@ -1730,7 +1756,6 @@ dependencies = [ "sdp-types", "smallvec", "thiserror", - "time 0.1.44", "tokio", "tokio-util", "url", diff --git a/Cargo.toml b/Cargo.toml index 6d0730a..ef7e539 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ categories = ["network-programming", "multimedia"] description = "high-level RTSP multimedia streaming library" repository = "https://github.com/scottlamb/retina" include = ["src/**/*", "benches", "Cargo.toml"] -rust-version = "1.67" +rust-version = "1.70" [package.metadata.docs.rs] # https://docs.rs/about/metadata @@ -29,6 +29,7 @@ futures = "0.3.14" h264-reader = "0.7.0" hex = "0.4.3" http-auth = "0.1.2" +jiff = "0.1.8" log = "0.4.8" once_cell = "1.7.2" pin-project = "1.0.7" @@ -38,7 +39,6 @@ rtsp-types = "0.1.0" sdp-types = "0.1.4" smallvec = { version = "1.6.1", features = ["union"] } thiserror = "1.0.25" -time = "0.1.43" tokio = { version = "1.11.0", features = ["macros", "net", "rt", "time"] } tokio-util = { version = "0.7.3", features = ["codec"] } url = "2.2.1" diff --git a/src/lib.rs b/src/lib.rs index 38de38b..ee8329f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -204,21 +204,11 @@ impl std::fmt::Display for NtpTimestamp { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let since_epoch = self.0.wrapping_sub(UNIX_EPOCH.0); let sec_since_epoch = (since_epoch >> 32) as u32; - let tm = time::at(time::Timespec { - sec: i64::from(sec_since_epoch), - nsec: 0, - }); - let ms = ((since_epoch & 0xFFFF_FFFF) * 1_000) >> 32; - let zone_minutes = tm.tm_utcoff.abs() / 60; - write!( - f, - "{}.{:03}{}{:02}:{:02}", - tm.strftime("%FT%T").map_err(|_| std::fmt::Error)?, - ms, - if tm.tm_utcoff > 0 { '+' } else { '-' }, - zone_minutes / 60, - zone_minutes % 60 - ) + let ns = i32::try_from(((since_epoch & 0xFFFF_FFFF) * 1_000_000_000) >> 32) + .expect("should be < 1_000_000_000"); + let tm = jiff::Timestamp::new(i64::from(sec_since_epoch), ns) + .expect("u32 sec should be valid Timestamp"); + std::fmt::Display::fmt(&tm, f) } } @@ -233,22 +223,17 @@ impl std::fmt::Debug for NtpTimestamp { /// /// Currently this just allows formatting via `Debug` and `Display`. #[derive(Copy, Clone, Debug)] -pub struct WallTime(time::Timespec); +pub struct WallTime(jiff::Timestamp); impl WallTime { fn now() -> Self { - Self(time::get_time()) + Self(jiff::Timestamp::now()) } } impl Display for WallTime { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt( - &time::at(self.0) - .strftime("%FT%T") - .map_err(|_| std::fmt::Error)?, - f, - ) + std::fmt::Display::fmt(&self.0, f) } }