From 01215c4178716846acf7dc7888e1391243b420de Mon Sep 17 00:00:00 2001 From: Joakim Soderlund Date: Sun, 31 Mar 2024 16:01:02 +0200 Subject: [PATCH] Migrate from Chrono English to Dateparser --- Cargo.lock | 48 ++++++++++++++++++++++-------------------- query/Cargo.toml | 2 +- query/src/optimizer.rs | 6 ++---- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a1d395..e5e0d39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,6 +32,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + [[package]] name = "autocfg" version = "1.2.0" @@ -76,9 +82,9 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "chrono" -version = "0.4.35" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" dependencies = [ "android-tzdata", "iana-time-zone", @@ -89,16 +95,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "chrono-english" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73d909da7eb4a7d88c679c3f5a1bc09d965754e0adb2e7627426cef96a00d6f" -dependencies = [ - "chrono", - "scanlex", -] - [[package]] name = "clipboard-win" version = "5.3.0" @@ -148,6 +144,18 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +[[package]] +name = "dateparser" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2ef451feee09ae5ecd8a02e738bd9adee9266b8fa9b44e22d3ce968d8694238" +dependencies = [ + "anyhow", + "chrono", + "lazy_static", + "regex", +] + [[package]] name = "either" version = "1.10.0" @@ -187,7 +195,7 @@ name = "fimfareader-query" version = "0.1.0" dependencies = [ "chrono", - "chrono-english", + "dateparser", "fimfareader", "nom", "rayon", @@ -268,9 +276,9 @@ checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "minimal-lexical" @@ -416,12 +424,6 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" -[[package]] -name = "scanlex" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088c5d71572124929ea7549a8ce98e1a6fd33d0a38367b09027b382e67c033db" - [[package]] name = "serde" version = "1.0.197" @@ -455,9 +457,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.55" +version = "2.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +checksum = "11a6ae1e52eb25aab8f3fb9fca13be982a373b8f1157ca14b897a825ba4a2d35" dependencies = [ "proc-macro2", "quote", diff --git a/query/Cargo.toml b/query/Cargo.toml index 0ccaa8a..b4d7c46 100644 --- a/query/Cargo.toml +++ b/query/Cargo.toml @@ -10,7 +10,7 @@ path = ".." [dependencies.chrono] version = "*" -[dependencies.chrono-english] +[dependencies.dateparser] version = "*" [dependencies.nom] diff --git a/query/src/optimizer.rs b/query/src/optimizer.rs index 9e9fa0a..d82dd72 100644 --- a/query/src/optimizer.rs +++ b/query/src/optimizer.rs @@ -1,9 +1,7 @@ //! Query optimizer. use chrono::prelude::*; - -use chrono_english::parse_date_string; -use chrono_english::Dialect; +use dateparser::parse_with_timezone; use regex::escape; use regex::RegexBuilder; @@ -71,7 +69,7 @@ fn intfn(f: IntFn, op: Operator, value: &str) -> Result { } fn dtufn(f: DtuFn, op: Operator, value: &str) -> Result { - let Ok(value) = parse_date_string(value, Utc::now(), Dialect::Uk) else { + let Ok(value) = parse_with_timezone(value, &Local) else { return Err(Error::query("Invalid value for date type")); };