From e68ec53845c20ba99ec86f673c4cd07247aa2e32 Mon Sep 17 00:00:00 2001 From: Anas Awadalla Date: Sat, 26 Sep 2026 07:19:13 +0300 Subject: [PATCH 1/2] fix(ordinal): accept eighth instead of eight as an ordinal --- src/items/ordinal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items/ordinal.rs b/src/items/ordinal.rs index afba61f..6e93e12 100644 --- a/src/items/ordinal.rs +++ b/src/items/ordinal.rs @@ -35,7 +35,7 @@ fn text_ordinal(input: &mut &str) -> ModalResult { "fifth" => 5, "sixth" => 6, "seventh" => 7, - "eight" => 8, + "eighth" => 8, "ninth" => 9, "tenth" => 10, "eleventh" => 11, From 80047a4ef59b4cb318aa103cc0aee97fc18af4e5 Mon Sep 17 00:00:00 2001 From: Anas Awadalla Date: Sun, 27 Sep 2026 05:15:15 +0300 Subject: [PATCH 2/2] test(ordinal): cover text ordinals and parse eighth through the full parser --- src/items/ordinal.rs | 36 ++++++++++++++++++++++++++++++++++++ src/lib.rs | 14 ++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/items/ordinal.rs b/src/items/ordinal.rs index 6e93e12..d80b32a 100644 --- a/src/items/ordinal.rs +++ b/src/items/ordinal.rs @@ -45,3 +45,39 @@ fn text_ordinal(input: &mut &str) -> ModalResult { }) .parse_next(input) } + +#[cfg(test)] +mod tests { + use super::ordinal; + + #[test] + fn text_ordinal() { + for (s, expected) in [ + ("last", -1), + ("this", 0), + ("next", 1), + ("first", 1), + ("third", 3), + ("fourth", 4), + ("fifth", 5), + ("sixth", 6), + ("seventh", 7), + ("eighth", 8), + ("ninth", 9), + ("tenth", 10), + ("eleventh", 11), + ("twelfth", 12), + ] { + let mut input = s; + assert_eq!(ordinal(&mut input).unwrap(), expected, "{s}"); + assert!(input.is_empty(), "{s}"); + } + } + + #[test] + fn invalid_text_ordinal() { + for mut s in ["eight", "second", "foo"] { + assert!(ordinal(&mut s).is_err(), "{s}"); + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 128baa9..86d8ca3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -521,6 +521,20 @@ mod tests { "2023-03-05 00:00:00 000000000" ); } + + #[test] + fn test_weekday_with_text_ordinal() { + let date = "2023-02-28 10:12:03" + .parse::() + .unwrap() + .to_zoned(TimeZone::system()) + .unwrap(); + + assert_eq!( + get_formatted_date(&date, "eighth monday"), + "2023-04-24 00:00:00 000000000" + ); + } } #[cfg(test)]