Fix interval parsing for different cases

This commit is contained in:
jude 2023-10-01 09:42:58 +01:00
parent 00579428a1
commit 2681280a39
4 changed files with 14 additions and 5 deletions

2
Cargo.lock generated
View File

@ -2173,7 +2173,7 @@ checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
[[package]]
name = "reminder-rs"
version = "1.6.43"
version = "1.6.44"
dependencies = [
"base64 0.21.4",
"chrono",

View File

@ -1,6 +1,6 @@
[package]
name = "reminder-rs"
version = "1.6.43"
version = "1.6.44"
authors = ["Jude Southworth <judesouthworth@pm.me>"]
edition = "2021"
license = "AGPL-3.0 only"

View File

@ -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,

View File

@ -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<Interval, Error> {
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);
}
}