diff --git a/Cargo.lock b/Cargo.lock index 0eeebd2..ab80bc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,15 +17,6 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" -[[package]] -name = "android_system_properties" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" -dependencies = [ - "libc", -] - [[package]] name = "annotate-snippets" version = "0.12.18" @@ -273,17 +264,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "chrono" -version = "0.4.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" -dependencies = [ - "iana-time-zone", - "num-traits", - "windows-link", -] - [[package]] name = "clap" version = "4.6.7" @@ -342,12 +322,6 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "core_detect" version = "1.0.0" @@ -869,30 +843,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "iana-time-zone" -version = "0.1.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "log", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - [[package]] name = "icu_collections" version = "2.4.0" @@ -1025,6 +975,41 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "jiff" +version = "0.2.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "175dc66334db3b9ab9985bf8b61cfed50dc16d20964bb47f9e479adcae984a7f" +dependencies = [ + "jiff-core", + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", +] + +[[package]] +name = "jiff-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e599b80292e597019b8b3e392de3f4bea2959ddfb8c7dff60e035e9e311a2c1b" +dependencies = [ + "log", +] + +[[package]] +name = "jiff-static" +version = "0.2.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7b1af7547d47354bc438d797e3854601bde8f8d185780c5ba4ab27afa54f1ba" +dependencies = [ + "jiff-core", + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "js-sys" version = "0.3.107" @@ -1233,6 +1218,21 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "portable-atomic-util" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" +dependencies = [ + "portable-atomic", +] + [[package]] name = "potential_utf" version = "0.1.6" @@ -1431,11 +1431,11 @@ dependencies = [ "anyhow", "async-trait", "axum", - "chrono", "clap", "glob", "hex", "hmac", + "jiff", "regex", "reqwest", "serde", @@ -2399,65 +2399,12 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "626c4bac6755d76ffc12cb01b2eac751db1996b9e0041de9aa02c8c211ddc82c" -[[package]] -name = "windows-core" -version = "0.62.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-implement" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "windows-interface" -version = "0.59.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-result" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" -dependencies = [ - "windows-link", -] - [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 0153718..787bc6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,6 @@ hmac = "0.13.0" sha2 = "0.11.1" hex = "0.4.3" regex = "1.13.1" -chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } +jiff = { version = "0.2", default-features = false, features = ["std"] } subtle = "2.6" sqlx = { version = "0.9.0", default-features = false, features = ["runtime-tokio", "tls-rustls", "sqlite", "postgres", "macros", "migrate"] } diff --git a/src/db.rs b/src/db.rs index 8ecdc2a..da09aaf 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,11 +1,19 @@ use anyhow::{Context, Result}; -use chrono::Utc; +use jiff::{Timestamp, tz::Offset}; use serde::{Deserialize, Serialize}; use sqlx::{FromRow, PgPool, SqlitePool}; use std::collections::HashMap; use std::path::{Path, PathBuf}; use tracing::info; +/// Current UTC time as RFC 3339 with a `+00:00` offset, the format every stored +/// `created_at` has; rows sort by this text. +pub fn now_rfc3339() -> String { + Timestamp::now() + .display_with_offset(Offset::UTC) + .to_string() +} + #[derive(Clone)] pub enum DbPool { Sqlite(SqlitePool), @@ -239,7 +247,7 @@ impl DbPool { /// Records an executed review run and returns its primary key. pub async fn record_review(&self, rec: &NewReviewRecord<'_>) -> Result { - let now = Utc::now().to_rfc3339(); + let now = now_rfc3339(); let sql = r#" INSERT INTO reviews (repo, pr_number, title, author, status, provider_used, pass1_candidates, pass2_filtered, verified_findings, @@ -313,7 +321,7 @@ impl DbPool { feedback_type: &str, reason: Option<&str>, ) -> Result { - let now = Utc::now().to_rfc3339(); + let now = now_rfc3339(); let sql = r#" INSERT INTO findings_feedback (repo, file_path, issue_title, feedback_type, reason, created_at) VALUES ($1, $2, $3, $4, $5, $6) @@ -419,6 +427,24 @@ impl DbPool { mod tests { use super::*; + #[test] + fn now_rfc3339_matches_stored_format() { + let now = now_rfc3339(); + // e.g. 2026-11-17T11:02:03.123456789+00:00, as chrono wrote it before. + let (stamp, offset) = now.split_at(now.len() - 6); + assert_eq!(offset, "+00:00", "{now}"); + let (date, time) = stamp.split_once('T').expect("date and time"); + assert_eq!(date.len(), 10, "{now}"); + assert_eq!( + &time[..8].replace(|c: char| c.is_ascii_digit(), "0"), + "00:00:00", + "{now}" + ); + assert!(time.len() == 8 || time.as_bytes()[8] == b'.', "{now}"); + // Text order must stay time order next to rows written earlier. + assert!(now.as_str() > "2026-01-01T00:00:00+00:00"); + } + #[tokio::test] async fn test_sqlite_in_memory_lifecycle() { let db = DbPool::connect("sqlite::memory:") diff --git a/src/server.rs b/src/server.rs index 2959ef9..a07baac 100644 --- a/src/server.rs +++ b/src/server.rs @@ -867,7 +867,7 @@ async fn spawn_review_job( pass2_verified: 0, duration_secs: 0, provider_used: provider_hint, - created_at: chrono::Utc::now().to_rfc3339(), + created_at: crate::db::now_rfc3339(), summary: if cur_publish { "Two-pass review executing (live publishing enabled).".to_string() } else {