From 772f40dc8313e2e63ed5ee394f254eea4dcf6a1d Mon Sep 17 00:00:00 2001 From: Milan Pramod Date: Mon, 23 Nov 2026 18:37:23 +0530 Subject: [PATCH] refactor(utils): replace chrono with jiff for time handling --- Cargo.lock | 236 ++++++++++++--------------------------------------- Cargo.toml | 2 +- src/utils.rs | 26 +++--- 3 files changed, 68 insertions(+), 196 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6df89f0a..408f30ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,15 +11,6 @@ dependencies = [ "memchr", ] -[[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 = "anstream" version = "1.0.0" @@ -97,12 +88,6 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" -[[package]] -name = "bumpalo" -version = "3.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" - [[package]] name = "cc" version = "1.10.0" @@ -136,19 +121,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", - "js-sys", - "num-traits", - "wasm-bindgen", - "windows-link", -] - [[package]] name = "clap" version = "4.6.7" @@ -257,12 +229,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cpufeatures" version = "0.3.1" @@ -298,11 +264,11 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" name = "diffutils" version = "0.6.0" dependencies = [ - "chrono", "codspeed-divan-compat", "ctor", "diff", "itoa", + "jiff 1.0.2", "pretty_assertions", "rand", "regex", @@ -453,7 +419,6 @@ dependencies = [ "futures-core", "futures-task", "pin-project-lite", - "slab", ] [[package]] @@ -480,30 +445,6 @@ version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" -[[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" @@ -646,9 +587,25 @@ version = "0.2.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fefca06093eeaed707a905795e68206da0edca4edef23d2a3997a3ddbee462aa" dependencies = [ - "jiff-core", - "jiff-static", - "jiff-tzdb-platform", + "jiff-core 0.1.4", + "jiff-static 0.2.42", + "jiff-tzdb-platform 0.1.3", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", + "windows-link", +] + +[[package]] +name = "jiff" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e77cbfb9fff4798e283c2d69dff39fc2c45e7da017e5ce95b654e46ea41236" +dependencies = [ + "jiff-core 1.0.1", + "jiff-static 1.0.2", + "jiff-tzdb-platform 1.0.0", "log", "portable-atomic", "portable-atomic-util", @@ -665,42 +622,67 @@ dependencies = [ "log", ] +[[package]] +name = "jiff-core" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b46a105a9874634dd96231021526bf24ca04955a5998c59a9c7666e634b7b8" +dependencies = [ + "log", +] + [[package]] name = "jiff-static" version = "0.2.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d3213549742662eea1a18e6c5af9be5dfbabeb7611ab71356a54928ec398f0" dependencies = [ - "jiff-core", + "jiff-core 0.1.4", "proc-macro2", "quote", "syn 2.0.119", ] +[[package]] +name = "jiff-static" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9067a0b23e5be3147d56b2dcf652b18e6b1364caca93fb157653b6fbcab23a9" +dependencies = [ + "jiff-core 1.0.1", + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "jiff-tzdb" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa8377070c6bae868759445e5a77f66d84f0b72f3a054bfb00e6d038b8282da7" +[[package]] +name = "jiff-tzdb" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12e71a1b68a875a44a33bb7a1dd84392cb77145a3367a552a3cfe6a4f5cf3afc" + [[package]] name = "jiff-tzdb-platform" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "875a5a69ac2bab1a891711cf5eccbec1ce0341ea805560dcd90b7a2e925132e8" dependencies = [ - "jiff-tzdb", + "jiff-tzdb 0.1.9", ] [[package]] -name = "js-sys" -version = "0.3.104" +name = "jiff-tzdb-platform" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e0c1080212aad755ea003d18543e8768dd432c48819efd73a7bf1e39b7a5a3a" +checksum = "dc65b284afcfa8f6cf189c7274c805505314a7ab975c60e1f548bff56525420e" dependencies = [ - "cfg-if", - "futures-util", - "wasm-bindgen", + "jiff-tzdb 1.0.0", ] [[package]] @@ -1007,12 +989,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "rustversion" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" - [[package]] name = "same-file" version = "1.0.6" @@ -1083,12 +1059,6 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" -[[package]] -name = "slab" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" - [[package]] name = "smallvec" version = "1.16.5" @@ -1348,7 +1318,7 @@ dependencies = [ "fluent", "fluent-syntax", "icu_locale", - "jiff", + "jiff 0.2.42", "libc", "nix", "os_display", @@ -1404,51 +1374,6 @@ dependencies = [ "syn 3.0.10", ] -[[package]] -name = "wasm-bindgen" -version = "0.2.127" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b70935747edd64d89de3efa29d73789b806c15798f8e7dca4d8ac356b50ce70" -dependencies = [ - "cfg-if", - "once_cell", - "rustversion", - "wasm-bindgen-macro", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.127" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77775f8f3f7217702089053b94958f8f54061a3f663417df76e19cbdcca29bc1" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.127" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e11d33f857dc2fb11b8bc75aee111aa9cbeb12cd9f25efd3d4c2a3dd4e235284" -dependencies = [ - "bumpalo", - "proc-macro2", - "quote", - "syn 2.0.119", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.127" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef64dbcc55df09c7e5a46182d181c2cfa3e925f3da937ea764728b4bbb9dcbf" -dependencies = [ - "unicode-ident", -] - [[package]] name = "wild" version = "2.2.1" @@ -1467,65 +1392,12 @@ dependencies = [ "windows-sys", ] -[[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.61.2" diff --git a/Cargo.toml b/Cargo.toml index fda7c9dd..aee7148d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,9 +17,9 @@ name = "diffutils" path = "src/main.rs" [dependencies] -chrono = "0.4.38" diff = "0.1.13" itoa = "1.0.11" +jiff = "1.0.2" regex = "1.10.4" same-file = "1.0.6" unicode-width = "0.2.0" diff --git a/src/utils.rs b/src/utils.rs index c7e527dc..d866c968 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -380,7 +380,6 @@ pub fn is_posix_locale(category: &str) -> bool { /// A file that was `missing` and compared as empty is dated at the Unix Epoch. /// If an error occurs, it returns the current system time pub fn get_modification_time(file_path: &str, style: TimestampStyle, missing: bool) -> String { - use chrono::{DateTime, Local}; use std::fs; use std::time::{SystemTime, UNIX_EPOCH}; @@ -392,12 +391,13 @@ pub fn get_modification_time(file_path: &str, style: TimestampStyle, missing: bo .unwrap_or(SystemTime::now()) }; - let modification_time: DateTime = modification_time.into(); + let zoned = + jiff::ZonedDateTime::try_from(modification_time).unwrap_or(jiff::ZonedDateTime::now()); let format = match style { - TimestampStyle::Iso => "%Y-%m-%d %H:%M:%S%.9f %z", + TimestampStyle::Iso => "%Y-%m-%d %H:%M:%S.%9f %z", TimestampStyle::Traditional => "%a %b %e %H:%M:%S %Y", }; - modification_time.format(format).to_string() + zoned.strftime(format).to_string() } pub fn format_failure_to_read_input_file( @@ -684,7 +684,6 @@ mod tests { #[test] fn set_time() { - use chrono::{DateTime, Local}; use std::time::SystemTime; use tempfile::NamedTempFile; @@ -694,8 +693,8 @@ mod tests { let _ = temp.as_file().set_modified(current); // format current time - let current: DateTime = current.into(); - let current: String = current.format("%Y-%m-%d %H:%M:%S%.9f %z").to_string(); + let zoned = jiff::ZonedDateTime::try_from(current).unwrap(); + let current: String = zoned.strftime("%Y-%m-%d %H:%M:%S.%9f %z").to_string(); // verify assert_eq!( @@ -706,7 +705,6 @@ mod tests { #[test] fn invalid_file() { - use chrono::{DateTime, Local}; use std::time::SystemTime; let invalid_file = "target/utils/invalid-file"; @@ -714,11 +712,13 @@ mod tests { // store current time before calling `get_modification_time` // Because the file is invalid, it will return SystemTime::now() // which will be greater than previously saved time - let current_time: DateTime = SystemTime::now().into(); - let m_time: DateTime = - get_modification_time(invalid_file, TimestampStyle::Iso, false) - .parse() - .unwrap(); + let current_time = jiff::Timestamp::try_from(SystemTime::now()).unwrap(); + let m_time: jiff::Timestamp = jiff::ZonedDateTime::strptime( + "%Y-%m-%d %H:%M:%S.%9f %z", + get_modification_time(invalid_file, TimestampStyle::Iso, false), + ) + .unwrap() + .timestamp(); assert!(m_time > current_time); }