From 2681280a39f3517621379ddf323223eee90a7f9d Mon Sep 17 00:00:00 2001 From: jude Date: Sun, 1 Oct 2023 09:42:58 +0100 Subject: [PATCH] Fix interval parsing for different cases --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/commands/reminder_cmds.rs | 2 +- src/interval_parser.rs | 13 +++++++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 385abd6..d5e92df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2173,7 +2173,7 @@ checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "reminder-rs" -version = "1.6.43" +version = "1.6.44" dependencies = [ "base64 0.21.4", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 139af81..06341a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reminder-rs" -version = "1.6.43" +version = "1.6.44" authors = ["Jude Southworth "] edition = "2021" license = "AGPL-3.0 only" diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index 3cbd1ef..05a4826 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -619,7 +619,7 @@ pub async fn multiline( )] pub async fn remind( ctx: ApplicationContext<'_>, - #[description = "A description of the time to set the reminder for"] + #[description = "The time (and optionally date) to set the reminder for"] #[autocomplete = "time_hint_autocomplete"] time: String, #[description = "The message content to send"] content: String, diff --git a/src/interval_parser.rs b/src/interval_parser.rs index f0d560b..cbde4c3 100644 --- a/src/interval_parser.rs +++ b/src/interval_parser.rs @@ -150,7 +150,7 @@ impl<'a> Parser<'a> { "hours" | "hour" | "hr" | "hrs" | "h" => (0, 0, n.mul(3600)?, 0), "days" | "day" | "d" => (0, n, 0, 0), "weeks" | "week" | "w" => (0, n.mul(7)?, 0, 0), - "months" | "month" | "M" => (n, 0, 0, 0), + "months" | "month" => (n, 0, 0, 0), "years" | "year" | "y" => (n.mul(12)?, 0, 0, 0), _ => { return Err(Error::UnknownUnit { @@ -255,7 +255,7 @@ impl<'a> Parser<'a> { /// assert_eq!(parse_duration("32ms"), Ok(Duration::new(0, 32_000_000))); /// ``` pub fn parse_duration(s: &str) -> Result { - Parser { iter: s.chars(), src: s, current: (0, 0, 0, 0) }.parse() + Parser { iter: s.to_lowercase().chars(), src: &s.to_lowercase(), current: (0, 0, 0, 0) }.parse() } #[cfg(test)] @@ -324,4 +324,13 @@ mod tests { assert_eq!(interval.day, 0); assert_eq!(interval.month, 120); } + + #[test] + fn parse_case() { + let interval = parse_duration("200 Seconds").unwrap(); + + assert_eq!(interval.sec, 200); + assert_eq!(interval.day, 0); + assert_eq!(interval.month, 0); + } }