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
Provenance
- Commit
803d1fd- Tree
ecadc49- Author
Thayne McCombs <astrothayne@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
a4fdad6- Parent 2
bbac767
5 files changed+89 added−190 removed
modified:src/filter/time.rs+24 added-24 removed
1-use chrono::{DateTime, Local, NaiveDate, NaiveDateTime};1+use jiff::{civil::DateTime, tz::TimeZone, Span, Timestamp, Zoned};2 3 use std::time::SystemTime;4 5 /// Filter based on time ranges.4 unmodified lines10 }11 12 impl 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 }39 40 pub fn before(ref_time: &SystemTime, s: &str) -> Option<TimeFilter> {41 TimeFilter::from_str(ref_time, s).map(TimeFilter::Before)17 unmodified lines59 use std::time::Duration;60 61 #[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();69 70 assert!(TimeFilter::after(&ref_time, "1min")71 .unwrap()46 unmodified lines118 assert!(TimeFilter::after(&ref_time, same_day)119 .unwrap()120 .applies_to(&t1m_ago));121 124- 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 lines139 .unwrap()140 .applies_to(&t1m_ago));141 142 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 linesmodified:tests/tests.rs+5 added-1 removed
6 unmodified lines7 use std::path::Path;8 use std::time::{Duration, SystemTime};9 use test_case::test_case;10 11+use jiff::Timestamp;12 use normpath::PathExt;13 use regex::escape;14 15 use crate::testenv::TestEnv;2272 unmodified lines2288 }2289 2290 #[cfg(test)]2291 fn 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 linesmodified:Cargo.lock+58 added-159 removed
10 unmodified lines11 "memchr",12 ]13 14 [[package]]15-name = "android-tzdata"16-version = "0.1.1"17-source = "registry+https://github.com/rust-lang/crates.io-index"18-checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"19-20-[[package]]21-name = "android_system_properties"22-version = "0.1.5"23-source = "registry+https://github.com/rust-lang/crates.io-index"24-checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"25-dependencies = [26- "libc",27-]28-29-[[package]]15 name = "anstream"16 version = "0.6.15"17 source = "registry+https://github.com/rust-lang/crates.io-index"18 checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"58 unmodified lines77 "nix 0.24.3",78 ]79 80 [[package]]96-name = "autocfg"97-version = "1.3.0"98-source = "registry+https://github.com/rust-lang/crates.io-index"99-checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"100-101-[[package]]81 name = "bitflags"82 version = "1.3.2"83 source = "registry+https://github.com/rust-lang/crates.io-index"84 checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"14 unmodified lines99 "serde",100 ]101 102 [[package]]124-name = "bumpalo"125-version = "3.16.0"126-source = "registry+https://github.com/rust-lang/crates.io-index"127-checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"128-129-[[package]]103 name = "cc"104 version = "1.1.13"105 source = "registry+https://github.com/rust-lang/crates.io-index"106 checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48"13 unmodified lines120 source = "registry+https://github.com/rust-lang/crates.io-index"121 checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"122 123 [[package]]151-name = "chrono"152-version = "0.4.39"153-source = "registry+https://github.com/rust-lang/crates.io-index"154-checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825"155-dependencies = [156- "android-tzdata",157- "iana-time-zone",158- "num-traits",159- "windows-targets",160-]161-162-[[package]]124 name = "clap"125 version = "4.5.31"126 source = "registry+https://github.com/rust-lang/crates.io-index"127 checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767"48 unmodified lines176 source = "registry+https://github.com/rust-lang/crates.io-index"177 checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"178 179 [[package]]219-name = "core-foundation-sys"220-version = "0.8.7"221-source = "registry+https://github.com/rust-lang/crates.io-index"222-checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"223-224-[[package]]180 name = "crossbeam-channel"181 version = "0.5.14"182 source = "registry+https://github.com/rust-lang/crates.io-index"183 checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471"86 unmodified lines270 dependencies = [271 "aho-corasick",272 "anyhow",273 "argmax",319- "chrono",274 "clap",275 "clap_complete",276 "crossbeam-channel",277 "ctrlc",1 unmodified line279 "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 lines347 "windows-sys 0.52.0",348 ]349 350 [[package]]397-name = "humantime"398-version = "2.1.0"399-source = "registry+https://github.com/rust-lang/crates.io-index"400-checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"401-402-[[package]]403-name = "iana-time-zone"404-version = "0.1.60"405-source = "registry+https://github.com/rust-lang/crates.io-index"406-checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"407-dependencies = [408- "android_system_properties",409- "core-foundation-sys",410- "iana-time-zone-haiku",411- "js-sys",412- "wasm-bindgen",413- "windows-core",414-]415-416-[[package]]417-name = "iana-time-zone-haiku"418-version = "0.1.2"419-source = "registry+https://github.com/rust-lang/crates.io-index"420-checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"421-dependencies = [422- "cc",423-]424-425-[[package]]351 name = "ignore"352 version = "0.4.23"353 source = "registry+https://github.com/rust-lang/crates.io-index"354 checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b"34 unmodified lines389 "libc",390 ]391 392 [[package]]468-name = "js-sys"469-version = "0.3.70"393+name = "jiff"394+version = "0.2.4"395 source = "registry+https://github.com/rust-lang/crates.io-index"471-checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a"396+checksum = "d699bc6dfc879fb1bf9bdff0d4c56f0884fc6f0d0eb0fba397a6d00cd9a6b85e"397 dependencies = [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 ]406 407 [[package]]408+name = "jiff-static"409+version = "0.2.4"410+source = "registry+https://github.com/rust-lang/crates.io-index"411+checksum = "8d16e75759ee0aa64c57a56acbf43916987b20c77373cb7e808979e02b93c9f9"412+dependencies = [413+ "proc-macro2",414+ "quote",415+ "syn",416+]417+418+[[package]]419+name = "jiff-tzdb"420+version = "0.1.3"421+source = "registry+https://github.com/rust-lang/crates.io-index"422+checksum = "962e1dfe9b2d75a84536cf5bf5eaaa4319aa7906c7160134a22883ac316d5f31"423+424+[[package]]425+name = "jiff-tzdb-platform"426+version = "0.1.2"427+source = "registry+https://github.com/rust-lang/crates.io-index"428+checksum = "a63c62e404e7b92979d2792352d885a7f8f83fd1d0d31eea582d77b2ceca697e"429+dependencies = [430+ "jiff-tzdb",431+]432+433+[[package]]434 name = "lazy_static"435 version = "1.5.0"436 source = "registry+https://github.com/rust-lang/crates.io-index"437 checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"84 unmodified lines522 "windows-sys 0.52.0",523 ]524 525 [[package]]569-name = "num-traits"570-version = "0.2.19"571-source = "registry+https://github.com/rust-lang/crates.io-index"572-checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"573-dependencies = [574- "autocfg",575-]576-577-[[package]]526 name = "once_cell"527 version = "1.19.0"528 source = "registry+https://github.com/rust-lang/crates.io-index"529 checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"530 531 [[package]]532+name = "portable-atomic"533+version = "1.11.0"534+source = "registry+https://github.com/rust-lang/crates.io-index"535+checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"536+537+[[package]]538+name = "portable-atomic-util"539+version = "0.2.4"540+source = "registry+https://github.com/rust-lang/crates.io-index"541+checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"542+dependencies = [543+ "portable-atomic",544+]545+546+[[package]]547 name = "proc-macro2"585-version = "1.0.86"548+version = "1.0.94"549 source = "registry+https://github.com/rust-lang/crates.io-index"587-checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"550+checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"551 dependencies = [552 "unicode-ident",553 ]554 555 [[package]]556 name = "quote"594-version = "1.0.36"557+version = "1.0.40"558 source = "registry+https://github.com/rust-lang/crates.io-index"596-checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"559+checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"560 dependencies = [561 "proc-macro2",562 ]563 90 unmodified lines654 checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"655 656 [[package]]657 name = "syn"695-version = "2.0.75"658+version = "2.0.100"659 source = "registry+https://github.com/rust-lang/crates.io-index"697-checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9"660+checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"661 dependencies = [662 "proc-macro2",663 "quote",664 "unicode-ident",93 unmodified lines758 "wit-bindgen-rt",759 ]760 761 [[package]]799-name = "wasm-bindgen"800-version = "0.2.93"801-source = "registry+https://github.com/rust-lang/crates.io-index"802-checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"803-dependencies = [804- "cfg-if",805- "once_cell",806- "wasm-bindgen-macro",807-]808-809-[[package]]810-name = "wasm-bindgen-backend"811-version = "0.2.93"812-source = "registry+https://github.com/rust-lang/crates.io-index"813-checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b"814-dependencies = [815- "bumpalo",816- "log",817- "once_cell",818- "proc-macro2",819- "quote",820- "syn",821- "wasm-bindgen-shared",822-]823-824-[[package]]825-name = "wasm-bindgen-macro"826-version = "0.2.93"827-source = "registry+https://github.com/rust-lang/crates.io-index"828-checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf"829-dependencies = [830- "quote",831- "wasm-bindgen-macro-support",832-]833-834-[[package]]835-name = "wasm-bindgen-macro-support"836-version = "0.2.93"837-source = "registry+https://github.com/rust-lang/crates.io-index"838-checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"839-dependencies = [840- "proc-macro2",841- "quote",842- "syn",843- "wasm-bindgen-backend",844- "wasm-bindgen-shared",845-]846-847-[[package]]848-name = "wasm-bindgen-shared"849-version = "0.2.93"850-source = "registry+https://github.com/rust-lang/crates.io-index"851-checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"852-853-[[package]]762 name = "winapi"763 version = "0.3.9"764 source = "registry+https://github.com/rust-lang/crates.io-index"765 checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"23 unmodified lines789 source = "registry+https://github.com/rust-lang/crates.io-index"790 checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"791 792 [[package]]885-name = "windows-core"886-version = "0.52.0"887-source = "registry+https://github.com/rust-lang/crates.io-index"888-checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"889-dependencies = [890- "windows-targets",891-]892-893-[[package]]793 name = "windows-sys"794 version = "0.52.0"795 source = "registry+https://github.com/rust-lang/crates.io-index"796 checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"85 unmodified linesmodified:Cargo.toml+1 added-6 removed
39 unmodified lines40414243444445464748495051525354555657585960615758596029 unmodified lines39 unmodified linesignore = "0.4.23"regex = "1.11.1"regex-syntax = "0.8"ctrlc = "3.2"humantime = "2.1"globset = "0.4"anyhow = "1.0"etcetera = "0.9"normpath = "1.1.1"crossbeam-channel = "0.5.14"clap_complete = {version = "4.5.44", optional = true}faccess = "0.2.4"jiff = "0.2.4"
[dependencies.clap]version = "4.5.31"features = ["suggestions", "color", "wrap_help", "cargo", "derive"]
[dependencies.chrono]version = "0.4.39"default-features = falsefeatures = ["std", "clock"]
[dependencies.lscolors]version = "0.20"default-features = falsefeatures = ["nu-ansi-term"]29 unmodified linesmodified:CHANGELOG.md+1 added
8 unmodified lines9 10 11 ## Changes12 13+- Replace `humantime` crate and `chrono` crate with `jiff` crate, see #1690 (@sorairolake)14 15 ## Other16 17 788 unmodified lines