From 3147b942412966fca5791c6dee870ca7d16e8027 Mon Sep 17 00:00:00 2001 From: youdie006 Date: Tue, 27 Oct 2026 23:12:18 +0900 Subject: [PATCH] fix(date): accept a period after abbreviated month names #334 let weekday names take an abbreviating dot (mon., tue.), but literal_month still parsed only alpha1, so jan. 5 2024 or 14-nov.-2022 were rejected, although the module doc quotes the GNU manual allowing "an abbreviating dot" and GNU date accepts them. --- src/items/date.rs | 31 ++++++++++++++++++------------- src/items/mod.rs | 24 ++++++++++++------------ src/lib.rs | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/items/date.rs b/src/items/date.rs index 2ff8333..6491396 100644 --- a/src/items/date.rs +++ b/src/items/date.rs @@ -268,21 +268,21 @@ fn literal3(input: &mut &str) -> ModalResult { /// Parse the name of a month (case-insensitive) fn literal_month(input: &mut &str) -> ModalResult { - s(alpha1) + s((alpha1, opt('.')).take()) .verify_map(|s: &str| { Some(match s { - "january" | "jan" => 1, - "february" | "feb" => 2, - "march" | "mar" => 3, - "april" | "apr" => 4, - "may" => 5, - "june" | "jun" => 6, - "july" | "jul" => 7, - "august" | "aug" => 8, - "september" | "sep" | "sept" => 9, - "october" | "oct" => 10, - "november" | "nov" => 11, - "december" | "dec" => 12, + "january" | "jan" | "jan." => 1, + "february" | "feb" | "feb." => 2, + "march" | "mar" | "mar." => 3, + "april" | "apr" | "apr." => 4, + "may" | "may." => 5, + "june" | "jun" | "jun." => 6, + "july" | "jul" | "jul." => 7, + "august" | "aug" | "aug." => 8, + "september" | "sep" | "sep." | "sept" => 9, + "october" | "oct" | "oct." => 10, + "november" | "nov" | "nov." => 11, + "december" | "dec" | "dec." => 12, _ => return None, }) }) @@ -480,6 +480,8 @@ mod tests { "14-nov2022", "14nov2022", "14nov 2022", + "14 nov. 2022", + "14-nov.-2022", ] { let old_s = s.to_owned(); assert_eq!(parse(&mut s).unwrap(), reference, "Format string: {old_s}"); @@ -529,6 +531,8 @@ mod tests { "nov 14 2022", "nov14 2022", "nov14, 2022", + "nov. 14, 2022", + "nov.14 2022", ] { let old_s = s.to_owned(); assert_eq!(parse(&mut s).unwrap(), reference, "Format string: {old_s}"); @@ -584,6 +588,7 @@ mod tests { "nov-14-2022", "nov---14---2022", "nov - 14 - 2022", + "nov.-14-2022", ] { let old_s = s.to_owned(); assert_eq!(parse(&mut s).unwrap(), reference, "Format string: {old_s}"); diff --git a/src/items/mod.rs b/src/items/mod.rs index 58c549b..617073f 100644 --- a/src/items/mod.rs +++ b/src/items/mod.rs @@ -134,18 +134,18 @@ pub(crate) fn parse_at_local + Clone>(input: S) -> Result