Iterate over Date<Utc>? [chrono]

I have a start and an end date and want to iterate over days in between, is that possible using chrono?

let from = Utc.ymd(2020, 12, 30);
let to = Utc.ymd(2021, 1, 2);
for date in from..=to { // Does not work
    println!("{}", date);
}

This gives a compilation about Step not beeing implemented for Date<Utc>. Is there a way I can provide a step for the range so I can iterate over it?

[Rust Playground] for complete example and exact error message.

Unfortunately Step is a nightly only trait. You're probably better off adding 1 day to the date at each iteration

Ok, I'll loop manually then. Thanks!

Chrono’s NaiveDate has an iter_days iterator that might be useful here. Or maybe a corresponding method could be added to chrono::Date in a future version.

2 Likes