Skip to content
Myr

Merge pull request #1690 from sorairolake/replace-humantime-with-jiff

Before adoption: this commit came in with the history the project adopted, so no landing records it.

chore(deps): Replace `humantime` and `chrono` with `jiff`

authored by Thayne McCombs · committed by GitHub · parents a4fdad6, bbac767 · Browse files · 5 files+89 added−190 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+89 added−190 removed

  • tests:+5 added−1 removed
  • other:+84 added−189 removed

5 files+89 added−190 removed

modified:src/filter/time.rs+24 added-24 removed
1use chrono::{DateTime, Local, NaiveDate, NaiveDateTime};1use jiff::{civil::DateTime, tz::TimeZone, Span, Timestamp, Zoned};23use std::time::SystemTime;45/// Filter based on time ranges.
4 unmodified lines
10}1112impl TimeFilter {13 fn from_str(ref_time: &SystemTime, s: &str) -> Option<SystemTime> {14 humantime::parse_duration(s)15 .map(|duration| *ref_time - duration)14 s.parse::<Span>()15 .and_then(|duration| {16 Zoned::try_from(*ref_time).and_then(|zdt| zdt.checked_sub(duration))17 })18 .ok()19 .or_else(|| {18 DateTime::parse_from_rfc3339(s)19 .map(|dt| dt.into())20 let local_tz = TimeZone::system();21 s.parse::<Timestamp>()22 .map(|ts| ts.to_zoned(TimeZone::UTC))23 .ok()24 .or_else(|| {22 NaiveDate::parse_from_str(s, "%F")23 .ok()?24 .and_hms_opt(0, 0, 0)?25 .and_local_timezone(Local)26 .latest()25 s.parse::<DateTime>()26 .map(|dt| local_tz.to_ambiguous_zoned(dt))27 .and_then(|zdt| zdt.later())28 .ok()29 })30 .or_else(|| {29 NaiveDateTime::parse_from_str(s, "%F %T")30 .ok()?31 .and_local_timezone(Local)32 .latest()33 })34 .or_else(|| {31 let timestamp_secs = s.strip_prefix('@')?.parse().ok()?;36 DateTime::from_timestamp(timestamp_secs, 0).map(Into::into)32 Timestamp::from_second(timestamp_secs)33 .map(|ts| ts.to_zoned(TimeZone::UTC))34 .ok()35 })38 .map(|dt| dt.into())36 })37 .map(SystemTime::from)38 }3940 pub fn before(ref_time: &SystemTime, s: &str) -> Option<TimeFilter> {41 TimeFilter::from_str(ref_time, s).map(TimeFilter::Before)
17 unmodified lines
59 use std::time::Duration;6061 #[test]62 fn is_time_filter_applicable() {65 let ref_time = NaiveDateTime::parse_from_str("2010-10-10 10:10:10", "%F %T")63 let local_tz = TimeZone::system();64 let ref_time = local_tz65 .to_ambiguous_zoned("2010-10-10 10:10:10".parse::<DateTime>().unwrap())66 .later()67 .unwrap()67 .and_local_timezone(Local)68 .latest()69 .unwrap()68 .into();6970 assert!(TimeFilter::after(&ref_time, "1min")71 .unwrap()
46 unmodified lines
118 assert!(TimeFilter::after(&ref_time, same_day)119 .unwrap()120 .applies_to(&t1m_ago));121124 let ref_time = DateTime::parse_from_rfc3339("2010-10-10T10:10:10+00:00")122 let ref_time = "2010-10-10T10:10:10+00:00"123 .parse::<Timestamp>()124 .unwrap()125 .into();126 let t1m_ago = ref_time - Duration::from_secs(60);127 let t10s_before = "2010-10-10T10:10:00+00:00";
11 unmodified lines
139 .unwrap()140 .applies_to(&t1m_ago));141142 let ref_timestamp = 1707723412u64; // Mon Feb 12 07:36:52 UTC 2024144 let ref_time = DateTime::parse_from_rfc3339("2024-02-12T07:36:52+00:00")143 let ref_time = "2024-02-12T07:36:52+00:00"144 .parse::<Timestamp>()145 .unwrap()146 .into();147 let t1m_ago = ref_time - Duration::from_secs(60);148 let t1s_later = ref_time + Duration::from_secs(1);
16 unmodified lines
modified:tests/tests.rs+5 added-1 removed
6 unmodified lines
7use std::path::Path;8use std::time::{Duration, SystemTime};9use test_case::test_case;1011use jiff::Timestamp;12use normpath::PathExt;13use regex::escape;1415use crate::testenv::TestEnv;
2272 unmodified lines
2288}22892290#[cfg(test)]2291fn change_file_modified<P: AsRef<Path>>(path: P, iso_date: &str) {2291 let st = humantime::parse_rfc3339(iso_date).expect("invalid date");2292 let st = iso_date2293 .parse::<Timestamp>()2294 .map(SystemTime::from)2295 .expect("invalid date");2296 let ft = filetime::FileTime::from_system_time(st);2297 filetime::set_file_times(path, ft, ft).expect("time modification failde");2298}2299
395 unmodified lines
modified:Cargo.lock+58 added-159 removed
10 unmodified lines
11 "memchr",12]1314[[package]]15name = "android-tzdata"16version = "0.1.1"17source = "registry+https://github.com/rust-lang/crates.io-index"18checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"1920[[package]]21name = "android_system_properties"22version = "0.1.5"23source = "registry+https://github.com/rust-lang/crates.io-index"24checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"25dependencies = [26 "libc",27]2829[[package]]15name = "anstream"16version = "0.6.15"17source = "registry+https://github.com/rust-lang/crates.io-index"18checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
58 unmodified lines
77 "nix 0.24.3",78]7980[[package]]96name = "autocfg"97version = "1.3.0"98source = "registry+https://github.com/rust-lang/crates.io-index"99checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"100101[[package]]81name = "bitflags"82version = "1.3.2"83source = "registry+https://github.com/rust-lang/crates.io-index"84checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
14 unmodified lines
99 "serde",100]101102[[package]]124name = "bumpalo"125version = "3.16.0"126source = "registry+https://github.com/rust-lang/crates.io-index"127checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"128129[[package]]103name = "cc"104version = "1.1.13"105source = "registry+https://github.com/rust-lang/crates.io-index"106checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48"
13 unmodified lines
120source = "registry+https://github.com/rust-lang/crates.io-index"121checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"122123[[package]]151name = "chrono"152version = "0.4.39"153source = "registry+https://github.com/rust-lang/crates.io-index"154checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825"155dependencies = [156 "android-tzdata",157 "iana-time-zone",158 "num-traits",159 "windows-targets",160]161162[[package]]124name = "clap"125version = "4.5.31"126source = "registry+https://github.com/rust-lang/crates.io-index"127checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767"
48 unmodified lines
176source = "registry+https://github.com/rust-lang/crates.io-index"177checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"178179[[package]]219name = "core-foundation-sys"220version = "0.8.7"221source = "registry+https://github.com/rust-lang/crates.io-index"222checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"223224[[package]]180name = "crossbeam-channel"181version = "0.5.14"182source = "registry+https://github.com/rust-lang/crates.io-index"183checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471"
86 unmodified lines
270dependencies = [271 "aho-corasick",272 "anyhow",273 "argmax",319 "chrono",274 "clap",275 "clap_complete",276 "crossbeam-channel",277 "ctrlc",
1 unmodified line
279 "etcetera",280 "faccess",281 "filetime",282 "globset",329 "humantime",283 "ignore",284 "jemallocator",285 "jiff",286 "libc",287 "lscolors",288 "nix 0.29.0",289 "normpath",
57 unmodified lines
347 "windows-sys 0.52.0",348]349350[[package]]397name = "humantime"398version = "2.1.0"399source = "registry+https://github.com/rust-lang/crates.io-index"400checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"401402[[package]]403name = "iana-time-zone"404version = "0.1.60"405source = "registry+https://github.com/rust-lang/crates.io-index"406checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"407dependencies = [408 "android_system_properties",409 "core-foundation-sys",410 "iana-time-zone-haiku",411 "js-sys",412 "wasm-bindgen",413 "windows-core",414]415416[[package]]417name = "iana-time-zone-haiku"418version = "0.1.2"419source = "registry+https://github.com/rust-lang/crates.io-index"420checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"421dependencies = [422 "cc",423]424425[[package]]351name = "ignore"352version = "0.4.23"353source = "registry+https://github.com/rust-lang/crates.io-index"354checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b"
34 unmodified lines
389 "libc",390]391392[[package]]468name = "js-sys"469version = "0.3.70"393name = "jiff"394version = "0.2.4"395source = "registry+https://github.com/rust-lang/crates.io-index"471checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a"396checksum = "d699bc6dfc879fb1bf9bdff0d4c56f0884fc6f0d0eb0fba397a6d00cd9a6b85e"397dependencies = [473 "wasm-bindgen",398 "jiff-static",399 "jiff-tzdb-platform",400 "log",401 "portable-atomic",402 "portable-atomic-util",403 "serde",404 "windows-sys 0.59.0",405]406407[[package]]408name = "jiff-static"409version = "0.2.4"410source = "registry+https://github.com/rust-lang/crates.io-index"411checksum = "8d16e75759ee0aa64c57a56acbf43916987b20c77373cb7e808979e02b93c9f9"412dependencies = [413 "proc-macro2",414 "quote",415 "syn",416]417418[[package]]419name = "jiff-tzdb"420version = "0.1.3"421source = "registry+https://github.com/rust-lang/crates.io-index"422checksum = "962e1dfe9b2d75a84536cf5bf5eaaa4319aa7906c7160134a22883ac316d5f31"423424[[package]]425name = "jiff-tzdb-platform"426version = "0.1.2"427source = "registry+https://github.com/rust-lang/crates.io-index"428checksum = "a63c62e404e7b92979d2792352d885a7f8f83fd1d0d31eea582d77b2ceca697e"429dependencies = [430 "jiff-tzdb",431]432433[[package]]434name = "lazy_static"435version = "1.5.0"436source = "registry+https://github.com/rust-lang/crates.io-index"437checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
84 unmodified lines
522 "windows-sys 0.52.0",523]524525[[package]]569name = "num-traits"570version = "0.2.19"571source = "registry+https://github.com/rust-lang/crates.io-index"572checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"573dependencies = [574 "autocfg",575]576577[[package]]526name = "once_cell"527version = "1.19.0"528source = "registry+https://github.com/rust-lang/crates.io-index"529checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"530531[[package]]532name = "portable-atomic"533version = "1.11.0"534source = "registry+https://github.com/rust-lang/crates.io-index"535checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"536537[[package]]538name = "portable-atomic-util"539version = "0.2.4"540source = "registry+https://github.com/rust-lang/crates.io-index"541checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"542dependencies = [543 "portable-atomic",544]545546[[package]]547name = "proc-macro2"585version = "1.0.86"548version = "1.0.94"549source = "registry+https://github.com/rust-lang/crates.io-index"587checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"550checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"551dependencies = [552 "unicode-ident",553]554555[[package]]556name = "quote"594version = "1.0.36"557version = "1.0.40"558source = "registry+https://github.com/rust-lang/crates.io-index"596checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"559checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"560dependencies = [561 "proc-macro2",562]563
90 unmodified lines
654checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"655656[[package]]657name = "syn"695version = "2.0.75"658version = "2.0.100"659source = "registry+https://github.com/rust-lang/crates.io-index"697checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9"660checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"661dependencies = [662 "proc-macro2",663 "quote",664 "unicode-ident",
93 unmodified lines
758 "wit-bindgen-rt",759]760761[[package]]799name = "wasm-bindgen"800version = "0.2.93"801source = "registry+https://github.com/rust-lang/crates.io-index"802checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"803dependencies = [804 "cfg-if",805 "once_cell",806 "wasm-bindgen-macro",807]808809[[package]]810name = "wasm-bindgen-backend"811version = "0.2.93"812source = "registry+https://github.com/rust-lang/crates.io-index"813checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b"814dependencies = [815 "bumpalo",816 "log",817 "once_cell",818 "proc-macro2",819 "quote",820 "syn",821 "wasm-bindgen-shared",822]823824[[package]]825name = "wasm-bindgen-macro"826version = "0.2.93"827source = "registry+https://github.com/rust-lang/crates.io-index"828checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf"829dependencies = [830 "quote",831 "wasm-bindgen-macro-support",832]833834[[package]]835name = "wasm-bindgen-macro-support"836version = "0.2.93"837source = "registry+https://github.com/rust-lang/crates.io-index"838checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"839dependencies = [840 "proc-macro2",841 "quote",842 "syn",843 "wasm-bindgen-backend",844 "wasm-bindgen-shared",845]846847[[package]]848name = "wasm-bindgen-shared"849version = "0.2.93"850source = "registry+https://github.com/rust-lang/crates.io-index"851checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"852853[[package]]762name = "winapi"763version = "0.3.9"764source = "registry+https://github.com/rust-lang/crates.io-index"765checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
23 unmodified lines
789source = "registry+https://github.com/rust-lang/crates.io-index"790checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"791792[[package]]885name = "windows-core"886version = "0.52.0"887source = "registry+https://github.com/rust-lang/crates.io-index"888checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"889dependencies = [890 "windows-targets",891]892893[[package]]793name = "windows-sys"794version = "0.52.0"795source = "registry+https://github.com/rust-lang/crates.io-index"796checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
85 unmodified lines
modified:Cargo.toml+1 added-6 removed
modified:CHANGELOG.md+1 added
8 unmodified lines
91011## Changes1213- Replace `humantime` crate and `chrono` crate with `jiff` crate, see #1690 (@sorairolake)1415## Other1617
788 unmodified lines