Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/items/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,21 @@ fn literal3(input: &mut &str) -> ModalResult<Date> {

/// Parse the name of a month (case-insensitive)
fn literal_month(input: &mut &str) -> ModalResult<u8> {
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,
})
})
Expand Down Expand Up @@ -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}");
Expand Down Expand Up @@ -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}");
Expand Down Expand Up @@ -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}");
Expand Down
24 changes: 12 additions & 12 deletions src/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,18 @@ pub(crate) fn parse_at_local<S: AsRef<str> + Clone>(input: S) -> Result<ParsedDa
/// month = dec_uint ;
/// day = dec_uint ;
///
/// literal_month = "january" | "jan"
/// | "february" | "feb"
/// | "march" | "mar"
/// | "april" | "apr"
/// | "may"
/// | "june" | "jun"
/// | "july" | "jul"
/// | "august" | "aug"
/// | "september" | "sept" | "sep"
/// | "october" | "oct"
/// | "november" | "nov"
/// | "december" | "dec" ;
/// literal_month = "january" | "jan" | "jan."
/// | "february" | "feb" | "feb."
/// | "march" | "mar" | "mar."
/// | "april" | "apr" | "apr."
/// | "may" | "may."
/// | "june" | "jun" | "jun."
/// | "july" | "jul" | "jul."
/// | "august" | "aug" | "aug."
/// | "september" | "sept" | "sep" | "sep."
/// | "october" | "oct" | "oct."
/// | "november" | "nov" | "nov."
/// | "december" | "dec" | "dec." ;
///
/// time = iso_time | meridiem_time ;
///
Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,24 @@ mod tests {
assert_eq!(parse_datetime("05/7/1987").unwrap(), expected);
assert_eq!(parse_datetime("05/07/1987").unwrap(), expected);
}

#[test]
fn month_abbreviation_with_period() {
let months = [
"jan.", "feb.", "mar.", "apr.", "may.", "jun.", "jul.", "aug.", "sep.", "oct.",
"nov.", "dec.",
];
for (i, month) in months.iter().enumerate() {
let input = format!("{month} 5 2024");
let actual = parse_datetime(&input).unwrap().expect_in_range();
assert_eq!(actual.month() as usize, i + 1, "{input}");
assert_eq!(actual.day(), 5, "{input}");
}

for input in ["sept. 5 2024", "june. 5 2024", "jan.. 5 2024"] {
assert!(parse_datetime(input).is_err(), "{input}");
}
}
}

#[cfg(test)]
Expand Down
Loading