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
2 changes: 1 addition & 1 deletion src/items/weekday.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(super) fn parse(input: &mut &str) -> ModalResult<Weekday> {
}

fn day(input: &mut &str) -> ModalResult<Day> {
s(alpha1)
s((alpha1, opt('.')).take())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test with the full parser, like parse_datetime("wed., 2024-01-03")
the existing "mon." unit tests already passed before, they don't check that the whole input was consumed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new commit

.verify_map(|s: &str| {
Some(match s {
"monday" | "mon" | "mon." => Day::Monday,
Expand Down
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,33 @@ mod tests {
"2023-03-05 00:00:00 000000000"
);
}

#[test]
fn test_weekday_abbreviation_with_period() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this empty line

let date = "2023-02-28 10:12:03"
.parse::<DateTime>()
.unwrap()
.to_zoned(TimeZone::system())
.unwrap();

for (weekday, expected) in [
("mon.", "2023-03-06 00:00:00 000000000"),
("tue.", "2023-02-28 00:00:00 000000000"),
("wed.", "2023-03-01 00:00:00 000000000"),
("thu.", "2023-03-02 00:00:00 000000000"),
("fri.", "2023-03-03 00:00:00 000000000"),
("sat.", "2023-03-04 00:00:00 000000000"),
("sun.", "2023-03-05 00:00:00 000000000"),
] {
assert_eq!(get_formatted_date(&date, weekday), expected, "{weekday}");
}

let actual = crate::parse_datetime("wed., 2024-01-03")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2024-01-03 is already a wednesday, could you please add a case like "mon., 2024-01-03" too?

.unwrap()
.expect_in_range();
assert_eq!(actual.strftime("%F %T").to_string(), "2024-01-03 00:00:00");
}
}

#[cfg(test)]
Expand Down
Loading