Skip to content

Commit c42e7dd

Browse files
committed
Fix bounds checking with missing bound.
Before this, checking that start and end are both before the current date when either one of start or end is missing didn't work.
1 parent a919df3 commit c42e7dd

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/main.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,25 +471,25 @@ fn fixup_bounds(
471471
fn check_bounds(start: &Option<Bound>, end: &Option<Bound>) -> anyhow::Result<()> {
472472
// current UTC date
473473
let current = Utc::today();
474-
match start.as_ref().zip(end.as_ref()) {
474+
match (start, end) {
475475
// start date is after end date
476-
Some((Bound::Date(start), Bound::Date(end))) if end < start => {
476+
(Some(Bound::Date(start)), Some(Bound::Date(end))) if end < start => {
477477
bail!(
478478
"end should be after start, got start: {} and end {}",
479479
start,
480480
end
481481
);
482482
}
483483
// start date is after current date
484-
Some((Bound::Date(start), _)) if start > &current => {
484+
(Some(Bound::Date(start)), _) if start > &current => {
485485
bail!(
486486
"start date should be on or before current date, got start date request: {} and current date is {}",
487487
start,
488488
current
489489
);
490490
}
491491
// end date is after current date
492-
Some((_, Bound::Date(end))) if end > &current => {
492+
(_, Some(Bound::Date(end))) if end > &current => {
493493
bail!(
494494
"end date should be on or before current date, got start date request: {} and current date is {}",
495495
end,
@@ -1202,13 +1202,25 @@ mod tests {
12021202
assert!(check_bounds(&Some(Bound::Date(start)), &Some(Bound::Date(end))).is_err());
12031203
}
12041204

1205+
#[test]
1206+
fn test_check_bounds_invalid_start_after_current_without_end() {
1207+
let start = chrono::Utc::today().succ();
1208+
assert!(check_bounds(&Some(Bound::Date(start)), &None).is_err());
1209+
}
1210+
12051211
#[test]
12061212
fn test_check_bounds_invalid_end_after_current() {
12071213
let start = chrono::Utc::today();
12081214
let end = chrono::Utc::today().succ();
12091215
assert!(check_bounds(&Some(Bound::Date(start)), &Some(Bound::Date(end))).is_err());
12101216
}
12111217

1218+
#[test]
1219+
fn test_check_bounds_invalid_end_after_current_without_start() {
1220+
let end = chrono::Utc::today().succ();
1221+
assert!(check_bounds(&None, &Some(Bound::Date(end))).is_err());
1222+
}
1223+
12121224
#[test]
12131225
fn test_nightly_finder_iterator() {
12141226
let start_date = Date::from_utc(NaiveDate::from_ymd(2019, 01, 01), Utc);

tests/cmd/start-in-future.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ERROR: start date must be on or before the current date. received start date request 9999-01-01UTC
1+
ERROR: start date should be on or before current date, got start date request: 9999-01-01UTC and current date is [..]UTC

0 commit comments

Comments
 (0)