Skip to content
Myr

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

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

authored by Shun Sakai · committed by Shun Sakai · parent 7d57f61 · Browse files · 4 files+35 added−178 removed
This commit

State

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

Diff stats

4 files+35 added−178 removed

  • other:+35 added−178 removed

4 files+35 added−178 removed

modified:src/filter/time.rs+21 added-25 removed
1use chrono::{DateTime, Local, NaiveDate, NaiveDateTime};2use jiff::{Span, Zoned};1use jiff::{civil::DateTime, tz::TimeZone, Span, Timestamp, Zoned};23use std::time::SystemTime;45/// Filter based on time ranges.
6 unmodified lines
12impl TimeFilter {13 fn from_str(ref_time: &SystemTime, s: &str) -> Option<SystemTime> {14 s.parse::<Span>()15 .and_then(|duration| {17 Zoned::try_from(*ref_time).and_then(|zoned| zoned.checked_sub(duration))16 Zoned::try_from(*ref_time).and_then(|zdt| zdt.checked_sub(duration))17 })19 .map(SystemTime::from)18 .ok()19 .or_else(|| {22 DateTime::parse_from_rfc3339(s)23 .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(|| {26 NaiveDate::parse_from_str(s, "%F")27 .ok()?28 .and_hms_opt(0, 0, 0)?29 .and_local_timezone(Local)30 .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(|| {33 NaiveDateTime::parse_from_str(s, "%F %T")34 .ok()?35 .and_local_timezone(Local)36 .latest()37 })38 .or_else(|| {31 let timestamp_secs = s.strip_prefix('@')?.parse().ok()?;40 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 })42 .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() {69 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()71 .and_local_timezone(Local)72 .latest()73 .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));121128 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 2024148 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:Cargo.lock+12 added-146 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",
69 unmodified lines
347 "windows-sys 0.52.0",348]349350[[package]]397name = "iana-time-zone"398version = "0.1.60"399source = "registry+https://github.com/rust-lang/crates.io-index"400checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"401dependencies = [402 "android_system_properties",403 "core-foundation-sys",404 "iana-time-zone-haiku",405 "js-sys",406 "wasm-bindgen",407 "windows-core",408]409410[[package]]411name = "iana-time-zone-haiku"412version = "0.1.2"413source = "registry+https://github.com/rust-lang/crates.io-index"414checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"415dependencies = [416 "cc",417]418419[[package]]351name = "ignore"352version = "0.4.23"353source = "registry+https://github.com/rust-lang/crates.io-index"354checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b"
40 unmodified lines
395source = "registry+https://github.com/rust-lang/crates.io-index"396checksum = "d699bc6dfc879fb1bf9bdff0d4c56f0884fc6f0d0eb0fba397a6d00cd9a6b85e"397dependencies = [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"
6 unmodified lines
415 "syn",416]417418[[package]]486name = "js-sys"487version = "0.3.70"419name = "jiff-tzdb"420version = "0.1.3"421source = "registry+https://github.com/rust-lang/crates.io-index"489checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a"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 = [491 "wasm-bindgen",430 "jiff-tzdb",431]432433[[package]]434name = "lazy_static"
87 unmodified lines
522 "windows-sys 0.52.0",523]524525[[package]]587name = "num-traits"588version = "0.2.19"589source = "registry+https://github.com/rust-lang/crates.io-index"590checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"591dependencies = [592 "autocfg",593]594595[[package]]526name = "once_cell"527version = "1.19.0"528source = "registry+https://github.com/rust-lang/crates.io-index"529checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
228 unmodified lines
758 "wit-bindgen-rt",759]760761[[package]]832name = "wasm-bindgen"833version = "0.2.93"834source = "registry+https://github.com/rust-lang/crates.io-index"835checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"836dependencies = [837 "cfg-if",838 "once_cell",839 "wasm-bindgen-macro",840]841842[[package]]843name = "wasm-bindgen-backend"844version = "0.2.93"845source = "registry+https://github.com/rust-lang/crates.io-index"846checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b"847dependencies = [848 "bumpalo",849 "log",850 "once_cell",851 "proc-macro2",852 "quote",853 "syn",854 "wasm-bindgen-shared",855]856857[[package]]858name = "wasm-bindgen-macro"859version = "0.2.93"860source = "registry+https://github.com/rust-lang/crates.io-index"861checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf"862dependencies = [863 "quote",864 "wasm-bindgen-macro-support",865]866867[[package]]868name = "wasm-bindgen-macro-support"869version = "0.2.93"870source = "registry+https://github.com/rust-lang/crates.io-index"871checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"872dependencies = [873 "proc-macro2",874 "quote",875 "syn",876 "wasm-bindgen-backend",877 "wasm-bindgen-shared",878]879880[[package]]881name = "wasm-bindgen-shared"882version = "0.2.93"883source = "registry+https://github.com/rust-lang/crates.io-index"884checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"885886[[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]]918name = "windows-core"919version = "0.52.0"920source = "registry+https://github.com/rust-lang/crates.io-index"921checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"922dependencies = [923 "windows-targets",924]925926[[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-1 removed
8 unmodified lines
91011## Changes1213- Replace `humantime` crate with `jiff` crate, see #1690 (@sorairolake)13- Replace `humantime` crate and `chrono` crate with `jiff` crate, see #1690 (@sorairolake)1415## Other1617
788 unmodified lines